Forum Moderators: coopster
I keep having serious issues with using mysql_fetch_array($result) and I don't know why. I have used it many times previously without issue. Here is the code I am using (I have added in a few items while trying to debug it).
function vendorReactivateList()
{
$query = "SELECT * FROM vendors";
$result = mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result);// used this to verify I was getting results (I am)
$returnValue ="centercontent_____<font size=\"3\">Inactive Vendors</font><br /><br />"; // this is just part of the output
while($row = mysql_fetch_array($result));
{
$name = $row["name"];
$active = $row["active"];
$vID = $row["vendorID"];
if($active!=1)// am only doing this to simplify query for debugging, later this will be eliminated and query will be more specific
{
$returnValue .=$name." ";
$returnValue .="<a href=\"#\" onclick=\"gensend('mode=9&vendorID=".$vID."&reactivate=vendor')\";>Reactivate</a><br />";
}
}
$returnValue .=$num;
$returnValue .= mysql_result($result,0,'name');//used this to again verify I am getting an accessible result, I am. I can even iterate through this to bypass my problem with mysql_fetch_array , but I want to solve that problem as it has occurred to me in another spot as well
return $returnValue ;
}
I swear I have looked at the syntax of the mysql_fetch_array syntax many times and can't see anything wrong. I am getting in the loop but it is not going through the array. I am seeing only one result without any values from the query (excluding my test with mysql_result($result,0,'name')). Any help would be very greatly appreciated as this issue is frustrating the heck out of me.
Thanks
Thanks for the response,
I only used the mysql_result($result,0,'name'); after I was having issues with the mysql_fetch_array to verify there was nothing wrong with my query. Even with it removed the mysql_fetch_array is not working.
I did a var_dump($row) and it returned bool(false) (this is with the mysql_result() removed).
I do use the mysql_result() in another part of my code but it is a completely separate query and I am using it as a workaround for this same issue.
Any further input would be greatly appreciated. Thanks again
while($row = mysql_fetch_array($result));
{
$name = $row["name"];
$active = $row["active"];
$vID = $row["vendorID"];
if($active!=1)// am only doing this to simplify query for debugging, later this will be eliminated and query will be more specific
{
$returnValue .=$name." ";
$returnValue .="<a href=\"#\" onclick=\"gensend('mode=9&vendorID=".$vID."&reactivate=vendor')\";>Reactivate</a><br />";
}
} Into:
while($row = mysql_fetch_array($result));
{
print_r($row);
} Let's find out whether the problem is inside the loop or outside. Tell me how many Array(....) you get.
I had to convert what you wanted me to do into:
while($row = mysql_fetch_array($result));
{
$returnValue .= print_r($row);
}
and returned the $returnValue because this is an AJAX response that needs to be parsed to be viewed but I think it is essentially the same.
Anyhow my resulting output was: 1
So I know I get in the loop but I should get 4 passes. In fact when I run mysql_num_rows($result); I get a result of 4.
thanks again for your help