lalnfl Posted February 15, 2011 Share Posted February 15, 2011 By not using the order by function in SQL. Like I have $match_1 and $segment_1. They are two seperate tables so how would I order them like the ORDER BY in sql. Is there a way to do that? Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/ Share on other sites More sharing options...
cyberRobot Posted February 15, 2011 Share Posted February 15, 2011 There are various sort functions available in PHP. Have you tried something like this: http://php.net/manual/en/function.sort.php Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174348 Share on other sites More sharing options...
lalnfl Posted February 15, 2011 Author Share Posted February 15, 2011 Would there be a way to sort without putting values into an array? Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174356 Share on other sites More sharing options...
btherl Posted February 15, 2011 Share Posted February 15, 2011 You could put the data into a file, sort the file with an external program and then read the data back in. Why do you want to avoid using arrays? Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174359 Share on other sites More sharing options...
lalnfl Posted February 15, 2011 Author Share Posted February 15, 2011 I don't now that you gave me that answer lol. Just not grasping what I want yet... Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174362 Share on other sites More sharing options...
btherl Posted February 15, 2011 Share Posted February 15, 2011 Do you want to merge (join) the two tables in SQL, and have SQL order them? Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174363 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 Post your code, maybe we can help you work out your sorting. If not, perhaps describe exactly what you want to do, maybe someone can offer a good solution to your issues. Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174377 Share on other sites More sharing options...
lalnfl Posted February 15, 2011 Author Share Posted February 15, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174399 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 Please post all of the code, including the queries. We need to be able to see all the information to really understand what you are trying to achieve, and instruct you on how to achieve it. Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174405 Share on other sites More sharing options...
lalnfl Posted February 15, 2011 Author Share Posted February 15, 2011 $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); Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174730 Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Author Share Posted February 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227697-how-would-order-things-not-using-sql/#findComment-1174749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.