Jump to content

How would order things not using SQL?


lalnfl

Recommended Posts

Do you want to merge (join) the two tables in SQL, and have SQL order them?

 

Merging is worth a shot. How would I merge the tables?

 

This is what I was trying to do, $get_segment is a mysql_fetch_array

 

$card = array("$get_segment");

	foreach ($card as $key => $row){

		$order[$key] = $row['order'];

	}

	$match = array_multisort($order, SORT_DESC, $card);

Link to comment
Share on other sites

$sql_get_match = mysql_query("SELECT * FROM Match_1v1 WHERE show_id='$show_id'");
while ($get_match = mysql_fetch_assoc($sql_get_match)){

	$match_id = $get_match['id'];
	$worker_id1 = $get_match['worker_id1'];
	$worker_id2 = $get_match['worker_id2'];
	$match_length = $get_match['length'];
	$match_preview = nl2br($get_match['preview']);
	$title_id = $get_match['title_id'];
	$match_base_id = $get_match['match_id'];
	$match_1v1_order = $get_match['order'];

	// get the match base

	$sql_get_base = mysql_query("SELECT * FROM Matches WHERE id='$match_base_id'");
	$get_base = mysql_fetch_array($sql_get_base);

	$match_base = $get_base['base'];

	// get the title

	$sql_get_title = mysql_query("SELECT * FROM Title WHERE id='$title_id'");
	$check_title = mysql_num_rows($sql_get_title);

	if ($check_title < 1){

		$match_title = "n/a";

	}

	else {

		$get_title = mysql_fetch_array($sql_get_title);

		$match_title = $get_title['name'];

	}

	// get worker 1

	$sql_get_worker = mysql_query("SELECT * FROM Worker WHERE id='$worker_id1'");
	$get_worker = mysql_fetch_array($sql_get_worker);

	$mem_id = $get_worker['mem_id'];
	$worker_firstname = $get_worker['firstname'];
	$worker_lastname = $get_worker['lastname'];

	$worker_1 = "$worker_firstname $worker_lastname";

	// get poser

	$check_pic = "Members/$mem_id/worker$worker_id1.jpg";
	$default_pic = "Members/0/default.jpg";

	if (file_exists($check_pic)){

		$worker_pic1 = "<img src='$check_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

	}

	else {

		$worker_pic1 = "<img src='$default_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

	}

	// get worker 2

	$sql_get_worker = mysql_query("SELECT * FROM Worker WHERE id='$worker_id2'");
	$get_worker = mysql_fetch_array($sql_get_worker);

	$mem_id = $get_worker['mem_id'];
	$worker_firstname = $get_worker['firstname'];
	$worker_lastname = $get_worker['lastname'];

	$worker_2 = "$worker_firstname $worker_lastname";

	// get poser

	$check_pic = "Members/$mem_id/worker$worker_id2.jpg";
	$default_pic = "Members/0/default.jpg";

	if (file_exists($check_pic)){

		$worker_pic2 = "<img src='$check_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

	}

	else {

		$worker_pic2 = "<img src='$default_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

	}

	// creative options

	if ($check_owner < 1 || $show_publish == "y"){

		$match_options = "";

	}

	else {

		$match_options = "<div align='center' style='width: 774px; margin: 3px;'>

		<a href='fed_events.php?promotion_id=$promo_id&show_id=$show_id&match_id=$match_id&match_base=$match_base&creative' style='font-weight: bold;'>CREATIVE ROOM</a>

		</div>";

	}

	// format the match output

	$match_1v1 .= "<div style='width: 780px; margin: 3px; border: 1px solid #000000; background-color: #a0a0a0;'>

	<div align='center' style='width: 372px; margin: 3px; float: left;'>

	<div align='center' style='width: 366px; margin: 3px;'>

	$worker_pic1

	</div>

	<div align='center' style='width: 366px; margin: 3px;'>

	$worker_1

	</div>

	</div>

	<div align='center' style='width: 18px; margin: 3px; margin-top: 75px; font-weight: bold; float: left;'>

	VS.

	</div>

	<div align='center' style='width: 372px; margin: 3px; float: left;'>

	<div align='center' style='width: 366px; margin: 3px;'>

	$worker_pic2

	</div>

	<div align='center' style='width: 366px; margin: 3px;'>

	$worker_2

	</div>

	</div>

	<div class='line'></div>

	<div align='center' style='width: 384px; margin: 3px; font-weight: bold; float: left;'>

	Length:

	</div>

	<div align='center' style='width: 384px; margin: 3px; float: left;'>

	$match_length minute(s)

	</div>

	<div class='line'></div>

	<div align='center' style='width: 384px; margin: 3px; font-weight: bold; float: left;'>

	Preview:

	</div>

	<div align='center' style='width: 384px; margin: 3px; float: left;'>

	$match_preview

	</div>

	<div class='line'></div>

	<div align='center' style='width: 384px; margin: 3px; font-weight: bold; float: left;'>

	Title:

	</div>

	<div align='center' style='width: 384px; margin: 3px; float: left;'>

	$match_title

	</div>

	<div class='line'></div>

	$match_options

	</div>";

}

// get the segments

	$sql_get_segment = mysql_query("SELECT * FROM Segment_1 WHERE show_id='$show_id'");
	while ($get_segment = mysql_fetch_assoc($sql_get_segment)){

		$segment_id = $get_segment['id'];
		$worker_id = $get_segment['worker_id'];
		$segment_name = $get_segment['name'];
		$segment_length = $get_segment['length'];
		$segment_1_order = $get_segment['order'];

		// get worker

		$sql_get_worker = mysql_query("SELECT * FROM Worker WHERE id='$worker_id'");
		$get_worker = mysql_fetch_array($sql_get_worker);

		$mem_id = $get_worker['mem_id'];
		$worker_firstname = $get_worker['firstname'];
		$worker_lastname = $get_worker['lastname'];

		// get poser

		$check_pic = "Members/$mem_id/worker$worker_id.jpg";
		$default_pic = "Members/0/default.jpg";

		if (file_exists($check_pic)){

			$worker_pic = "<img src='$check_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

		}

		else {

			$worker_pic = "<img src='$default_pic' width='150px' height='150px' alt='$worker_firstname $worker_lastname' />";

		}

		// creative options

		if ($check_owner < 1 || $show_publish == "y"){

			$segment_options = "";

		}

		else {

			$segment_options = "<div align='center' style='width: 774px; margin: 3px;'>

			<a href='fed_events.php?promotion_id=$promo_id&show_id=$show_id&segment_id=$segment_id&segment_base=1&creative' style='font-weight: bold;'>CREATIVE ROOM</a>

			</div>";

		}

		// format the content

		$segment_1 .= "<div style='width: 780px; margin: 3px; border: 1px solid #000000; background-color: #a0a0a0;'>

		<div align='center' style='width: 774px; margin: 3px; font-weight: bold;'>

		$segment_name

		</div>

		<div align='center' style='width: 774px; margin: 3px;'>

		$worker_pic

		</div>

		<div align='center' style='width: 774px; margin: 3px;'>

		$worker_firstname $worker_lastname

		</div>

		<div align='center' style='width: 384px; margin: 3px; font-weight: bold; float: left;'>

		Length:

		</div>

		<div align='center' style='width: 384px; margin: 3px; float: left;'>

		$segment_length minute(s)

		</div>

		<div class='line'></div>

		$segment_options

		</div>";

	}

	$card = array("$get_segment" => "$segment_1", "$get_match" => "$match1v1");

	foreach ($card as $key => $row){

		$order[$key] = $row['order'];

	}

	$match = array_multisort($order, SORT_DESC, $card);

Link to comment
Share on other sites

I have 2 results from the $get_segment and 1 result from the $get_match. But when I go ahead and sort them, even though 1 of the orders on $get_segment have a 1 and the other a 3 and the order on the $get_match is a 2. So that is how it should display, but it doesn't, it displays the $get_segment together and then the $get_match. I want to know how I can split the array.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.