marukochan Posted September 6, 2007 Share Posted September 6, 2007 Can someone point out to me what is wrong with this code? It suppose to print out the company id with "Awarded" status, but instead it prints out ALL the company id regardless it is "Awarded" or "Bidding". $status = "Awarded"; $query = mysql_query ("SELECT * FROM project WHERE project_status = '$status'"); $result= mysql_num_rows($query); while($row=mysql_fetch_array($query)) { print $row["company_id"]; echo ("<br>"); } Thanks. Link to comment https://forums.phpfreaks.com/topic/68185-what-is-wrong-with-my-query/ Share on other sites More sharing options...
beboo002 Posted September 6, 2007 Share Posted September 6, 2007 while($row=mysql_fetch_array($query)) change here something like while($row=mysql_fetch_array($result)) Link to comment https://forums.phpfreaks.com/topic/68185-what-is-wrong-with-my-query/#findComment-342802 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 With this data [pre] id, company_id, project_status 1, 1, 'Awarded' 2, 2, 'Bidding' 3, 3, 'Awarded' 4, 4, 'Bidding' [/pre] your code gave 1 3 So I'd check your data @beeboo if the query result is in $query, why do you suggest using $result, which would contain the number of rows? Link to comment https://forums.phpfreaks.com/topic/68185-what-is-wrong-with-my-query/#findComment-342810 Share on other sites More sharing options...
beboo002 Posted September 6, 2007 Share Posted September 6, 2007 while($row=mysql_fetch_array($query)) this query gives error like this Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\adminajax\home1.php on line 352 so he is not found any result and sceond qus. is when arise when query gives any result Link to comment https://forums.phpfreaks.com/topic/68185-what-is-wrong-with-my-query/#findComment-342815 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 It may give an error with your code. It doesn't with his. Link to comment https://forums.phpfreaks.com/topic/68185-what-is-wrong-with-my-query/#findComment-342818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.