SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Loop Help
-
Jun 7, 2001, 09:41 #1
- Join Date
- May 2001
- Location
- Singapore
- Posts
- 91
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Loop Help
hi all. i need some help with this loop problem. Someone told me it is inefficient if it worked the way i wanted it to work and the output only shows 1 result. I know i must put the $sql4 statement inside the $sql3 while loop but i simply just can't get it to work. Any Help appreciated
What my loop does:
sql3 will select all data from a table when a column Gameid equals to another id number. sql4 will select data when $Hid from sql3 matches another field Called Hid too in table (xiccc.CodeCreators)
However it does only shows 1 result
Code:
$sql3 = "SELECT * FROM xiccc.$table2
WHERE Gameid='$Id' ORDER BY Territory ASC";
$db->query($sql3);
while ($db->next_record()) {
$Territory = $db->f(Territory);
$TotalCodes = $db->f(TotalCodes);
$Date = $db->f(Date);
$Hid = $db->f(Hid);
}
$sql4 = "SELECT Nick, Email FROM xiccc.CodeCreators
WHERE Hid='$Hid'";
$db->query($sql4);
while ($db->next_record()) {
$Nick = $db->f(Nick);
$Email = $db->f(Email);
$color = ($i++ % 2 ) ? '#000000' : '#333333';
$tmp3 = "<tr bgcolor='$color'><td> <font size='2' face='Verdana, Arial'><a href='http://www.xplodercodes.com/codes/dreamcast/codes/codes.phtml?id=$Id'>$Territory</a></font></td><td> <font size='2' face='Verdana, Arial'>$TotalCodes</font></td><td> <font size='2' face='Verdana, Arial'>$Date</font></td><td> <font size='2' face='Verdana, Arial'><a href='mailto:$Email'>$Nick</a></font></td></tr>";
$t->set_var('data', $tmp3);
$t->parse('CBlock', 'CodesBlock', true);
}
Last edited by XploreR; Jun 7, 2001 at 10:19.
-
Jun 7, 2001, 10:19 #2
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try the following code...it is inefficient as you'd have allot of queries!!!
Code:$sql3 = "SELECT * FROM xiccc.$table2 WHERE Gameid='$Id' ORDER BY Territory ASC"; $db->query($sql3); while ($db->next_record()) { $Territory = $db->f(Territory); $TotalCodes = $db->f(TotalCodes); $Date = $db->f(Date); $Hid = $db->f(Hid); $sql4 = "SELECT Nick, Email FROM xiccc.CodeCreators WHERE Hid='$Hid'"; $db->query($sql4); while ($db->next_record()) { $Nick = $db->f(Nick); $Email = $db->f(Email); $color = ($i++ % 2 ) ? '#000000' : '#333333'; $tmp3 = "<tr bgcolor='$color'><td> <font size='2' face='Verdana, Arial'> <a href='http://www.xplodercodes.com/codes/dreamcast/codes/codes.phtml?id=$Id'>$Territory</a></font> </td><td> <font size='2' face='Verdana, Arial'>$TotalCodes</font></td><td> <font size='2' face='Verdana, Arial'>$Date</font></td><td> <font size='2' face='Verdana, Arial'> <a href='mailto:$Email'>$Nick</a> </font></td></tr>"; $t->set_var('data', $tmp3); $t->parse('CBlock', 'CodesBlock', true); } }
Last edited by petesmc; Jun 7, 2001 at 10:24.
-
Jun 7, 2001, 20:12 #3
- Join Date
- May 2001
- Location
- Singapore
- Posts
- 91
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It dosen't work either as it now shows the last result. Any help guys? I think it's to do with the parsing part or setting the variable?
Last edited by XploreR; Jun 7, 2001 at 21:04.
Bookmarks