Code Used(db connection already established):
<?php
$cur = mysql_query("SELECT MAX(id) FROM trades");
echo "$cur";
while($cur >= 0) {
$query = mysql_query("SELECT * FROM trades WHERE id='$cur'");
if(mysql_num_rows($query)==0) {
echo "ERROR!";
exit();
}
$row = mysql_fetch_assoc($query);
$tradeID = $row['ID'];
$mcUsername = $row['Minecraft Username'];
$blockID = $row['Block ID'];
$quantity = $row['Quantity'];
$costPer = $row['CostPer'];
$tradeNotes = $row['TradeNotes'];
echo "<tr>";
echo "<td class='first-td'>$tradeID</td>";
echo "<td>$mcUsername</td>";
echo "<td>$blockID</td>";
echo "<td>$quantity</td>";
echo "<td>$costPer</td>";
echo "<td class='last-td'>$tradeNotes</td>";
echo "</tr>";
$cur = "$cur - 1";
}
?>
The echo of the $cur is returning : Resource id #7
And the if statement is returning ERROR, which is most likely caused due to $cur not working right.
Is there some kind of syntax error in what I’m doing because when I run the SQL query for $cur manually in MySQL DB it returns the expected value.
Try this
mysql_queryreturns a resource for select query not a value. Check what is returned by mysql_query and notice the warning against using mysql_ function