hackerkts Posted June 28, 2006 Share Posted June 28, 2006 I have stored informations in database, and I wanna loop them out.Let's say I have 20 rows of informations in database, and I wanna echo them out by putting them in this format.[code]<table width="234" border="1"> <tr> <td><div align="center">Index1</div></td> <td><div align="center">File1</div></td> <td><div align="center">Index10</div></td> <td><div align="center">File10</div></td> </tr></table>[/code][code] <tr> <td><div align="center">Index1</div></td> <td><div align="center">File1</div></td> <td><div align="center">Index10</div></td> <td><div align="center">File10</div></td> </tr>[/code]Basically, it's just look like:|Index1|File1|Index11|File11||Index2|File2|Index12|File12||Index3|File3|Index13|File13||Index4|File4|Index14|File14||Index5|File5|Index15|File15||Index6|File6|Index16|File16||Index7|File7|Index17|File17||Index8|File8|Index18|File18||Index9|File9|Index19|File19||Index10|File10|Index20|File20|I only could think of making 2 queries but I can't figure out how to do 2 queries in 1 loop.Anyone has an idea ? Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/ Share on other sites More sharing options...
wildteen88 Posted June 28, 2006 Share Posted June 28, 2006 Prehaps having a read of [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95443\" target=\"_blank\"]this thread[/a] may help. Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50416 Share on other sites More sharing options...
hackerkts Posted June 28, 2006 Author Share Posted June 28, 2006 I have read that, but I still can't get 2 query working on the same loop.I would either get a page which keeps loading (some problem with the scripts, it just keep looping and does the query) or not working properly.Do you have another suggestion ?Btw... Thanks for replying. Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50419 Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 May I ask why you think you need to make two queries? What you described sounded like a single query would work. Something like...$_q = "SELETC * FROM $_table";then take the result and$_string = '<table>';while ($_data = mysql_fetch_array($result, MYSQL_NUM)) // something like this, I'll let you double check{$_string .= '<tr><td>' . $_data[0] . '</td>' . '<td>' .$_data[1] . '</td>' ... etc etc ;}$_string .= '</table>';echo $_string; Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50425 Share on other sites More sharing options...
radalin Posted June 28, 2006 Share Posted June 28, 2006 You could try a thing like$res1 = mysql_query("select * from foo order by id asc limit 0,10");$res2 = mysql_query("select * from foo order by id asc limit 10,10")which means you have two queries which one begins from 0th index and other from 10thand your loop should be something like[code]while ($row = mysql_fetch_row($res1) ){echo $row[0] . $row[1];$row = mysql_fetch_row($res2)echo $row[0] . $row[1];}[/code]It should work. Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50426 Share on other sites More sharing options...
hackerkts Posted June 28, 2006 Author Share Posted June 28, 2006 Sorry for the late reply, thanks for replying and helping me.As to why I think I need 2 queries because I still doesn't get array into hand.Array is a weird thing :(I will try the examples now, thanks again. :D Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50437 Share on other sites More sharing options...
hackerkts Posted June 28, 2006 Author Share Posted June 28, 2006 Sorry for the double post, I just wanna say thanks !It's working now :D Link to comment https://forums.phpfreaks.com/topic/13111-2-queries-in-a-loop/#findComment-50447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.