|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
2 queries, loop once for every record
I have 2 queries. One is a list of books, the other is a list of stores.
I want to display the list of books in table rows (no problem), and list each store in columns next to the book name. example: book1 store1 store2 store3 book2 store1 store2 store3 book3 store1 store2 store3 book4 store1 store2 store3 I am having a problem looping through the mysql array for the stores on every row....it just comes back blank. when I pull the loop outside of the book loop, it works, so I guess I don't understand how to nest them correctly. Can someone show me a really rough example so I can see what I am doing wrong? Thanks in advance, B |
|
#2
|
|||
|
|||
|
Try this:
$sql1 = "SELECT * FROM table1"; $query1 = mysql_query($sql1,$connection); if(mysql_num_rows($query1)) { print "<table>"; while($rs1 = mysql_fetch_array($query1)) { print "<tr><td>"; print $rs1['book']; print "</td>"; $sql2 = "SELECT * FROM table2"; $query2 = mysql_query($sql2,$connection); if(mysql_num_rows($query2)) { while($rs2 = mysql_fetch_array($query2)) { print "<td>"; print $rs2['store']; print "</td>"; } } print "</tr>"; } } else { print "No results!"; }
__________________
Regards, Ramiro Varandas Jr. Last edited by ramz : February 22nd, 2003 at 02:58 AM. |
|
#3
|
|||
|
|||
|
Is there a way to just query the stores once, then refer to the query several times? It seems to me to be inefficient to query the database every time I loop through the book names...
|
|
#4
|
|||
|
|||
|
Yes! sure!
PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > 2 queries, loop once for every record |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|