PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$getunitid = @mysql_query("SELECT unitid FROM units WHERE name = '$newingname'");
if(!$getunitid)
{
echo'<p>fail ' . mysql_error() . '</p>';
}
while ($row = mysql_fetch_array($getunitid))
{
$unitid = $row['unitid'];
echo"test ok!";
echo"$unitid";
}
what this code should do is run a select statement and then pass the output to a variable and display it.
The query runs fine as fail is not outputted. however the next part is the problem. test ok is not out put. therefore i think there must be something wrong with my statement but i dont know what. can anyone heklp?
thanks
Try running your query result through mysql_num_rows() to see if you actually have data coming out. The query could be a 0 count result which would not fire an error but still not give you anything to loop over.
Failure and 0 results are not the same thing. Failure occurs when there is a problem with the query. The query can run successfully and still return no results. What this query is asking is:
# Get all `unitid` columns from all rows in the `units` table where the column `name` is exactly equal to the value in $newingname
SELECT unitid FROM units WHERE name = '$newingname';
I would suspect the 0 result is because there are no `name` values that match whatever value is in the $newingname variable.
ive sorted it! u cant see what the problem was from the code ive posted. it was further up in the code! thanks a lot again for all your help it really is appreciated!