MDanz Posted February 25, 2011 Share Posted February 25, 2011 i've been doing while loops for this problem .. i dont think its the right way though. i have a set of boxes each with a boxid(apart from the first), which is the id(mysql) of the previous box. e.g. box 1 has id 1 box 2 has id 2 and boxid 1, box 3 has id 3 and boxid 2 etc you see the boxid is the same as the previous id. i want 10 boxes to display , when i'm trying to loop this i am using a while loop, but i keep on having to use another while loop inside, just to match the boxid with previous id, to get the next box to display. so i would have to do 10 while loops inside one another, which isn't good practice. is there a better way to do this? for loop? another example e.g. box 1 has id 239 box 2 has id 456 and boxid 239, box 3 has id 123 and boxid 456 etc Link to comment https://forums.phpfreaks.com/topic/228756-loop-help/ Share on other sites More sharing options...
Pikachu2000 Posted February 25, 2011 Share Posted February 25, 2011 Where are these values coming from? Link to comment https://forums.phpfreaks.com/topic/228756-loop-help/#findComment-1179385 Share on other sites More sharing options...
MDanz Posted February 25, 2011 Author Share Posted February 25, 2011 the id comes from mysql. when i add a new box, the boxid is the id of the previous box and so on. Link to comment https://forums.phpfreaks.com/topic/228756-loop-help/#findComment-1179386 Share on other sites More sharing options...
MDanz Posted February 25, 2011 Author Share Posted February 25, 2011 [id=239] [id=456,boxid=239][id=123,boxid=456] how would you go about doing this? instead of multiple while loops inside each other. i've been doing mysql_query select boxid='$previousid' and then doing while loop inside while loop per box. there must be a better way. Link to comment https://forums.phpfreaks.com/topic/228756-loop-help/#findComment-1179391 Share on other sites More sharing options...
Pikachu2000 Posted February 25, 2011 Share Posted February 25, 2011 From your description, I'd be inclined to read the query results into an array, then go through that array with php to format the output. Running queries in loops is a resource hog. Link to comment https://forums.phpfreaks.com/topic/228756-loop-help/#findComment-1179392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.