PDA

View Full Version : MySQL result set problem


aquachimera
07-29-2008, 06:51 PM
I'm having an issue retrieving and then printing a multi-row result set from a mysql database. I'm trying to use the following php code to retrieve the data and then print it.

if ($racenum == 3) {
$result4 = mysql_query(
"select * ".
"from -database.table- where ".
"race1allow = '3' ORDER BY unitID"
);

if (mysql_num_rows($result4)>0) {
while ($row4 = mysql_fetch_assoc($result4)) {
print "<tr> <td><br>{$row4['uname']}</td>\n";
print "<td>{$row4['uexp']}</td></tr>\n";
}
print "</table> </td><td width='300'>\n";
}

The odd thing is that I have a similar statement elsewhere in my site that works fine using this code:

if ($racenum == 3) {
$result3 = mysql_query(
"select * ".
"from -database.table- where ".
"race3allow = '1' ORDER BY unitID"
);

if (mysql_num_rows($result3)>0) {
while ($row = mysql_fetch_assoc($result3)) {

print "<tr> <td><br>{$row['uname']}</td>\n";
print "<td>{$row['uatk']}</td>\n";
print "<td>{$row['udef']}</td>\n";
print "<td>{$row['ustl']}</td>\n";
print "<td>{$row['uexp']}</td>\n";
print "<td>{$row['ucost']}</td>\n";
print "<td>{$row['pvalue']}</td></tr>\n";
}
print "</table></td><td>\n";
}

Can anybody see the difference that is making the second one work while the first one doesn't? They call the exact same rows from the exact same table, the only difference is the top one prints fewer entries from those rows.

Fumigator
07-30-2008, 12:02 AM
Why don't you have error checking on the query? I bet if you echo the error when the query fails the problem will become obvious.

aquachimera
07-30-2008, 12:39 AM
OK, I found the problem, it didn't actually spit out an error since my dyslexic typo created an empty result set, but now everything works, thanks for your help.