djfox Posted October 29, 2008 Share Posted October 29, 2008 Here`s my code: <?php $res = mysql_query("SELECT bought FROM userdata WHERE id='$logged'"); $a = mysql_fetch_row($res); $it = explode(",", $a[0]); foreach ($it as $th) { $res2 = mysql_query("SELECT id, shortname, type, name, cost FROM clothing WHERE id='$th'"); $b = mysql_fetch_row($res2); mysql_free_result($res2); echo "$b[3] <br>"; } ?> I want the end results to be listed in the order of the id numbers (listed in both as $b[0] and $th). How do I tell my code to list the results in numerical order? Link to comment https://forums.phpfreaks.com/topic/130508-solved-listing-foreach-list-in-a-certain-order/ Share on other sites More sharing options...
genericnumber1 Posted October 29, 2008 Share Posted October 29, 2008 Sort the array first? see: sort() Link to comment https://forums.phpfreaks.com/topic/130508-solved-listing-foreach-list-in-a-certain-order/#findComment-677063 Share on other sites More sharing options...
djfox Posted October 29, 2008 Author Share Posted October 29, 2008 It doesn`t work that way for this, I already tried. Link to comment https://forums.phpfreaks.com/topic/130508-solved-listing-foreach-list-in-a-certain-order/#findComment-677064 Share on other sites More sharing options...
genericnumber1 Posted October 29, 2008 Share Posted October 29, 2008 Sorry, were you replying to me before the edit or after? I really didn't look closely at your code at first thought I caught the edit before you saw. Link to comment https://forums.phpfreaks.com/topic/130508-solved-listing-foreach-list-in-a-certain-order/#findComment-677067 Share on other sites More sharing options...
djfox Posted October 29, 2008 Author Share Posted October 29, 2008 I replied before the edit. Ok, thanks, I`ll give it a try. Link to comment https://forums.phpfreaks.com/topic/130508-solved-listing-foreach-list-in-a-certain-order/#findComment-677069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.