简体   繁体   中英

MySQL Query not printing out data

I'm trying to retrieve some data from my table only for some reason I cant get it to return anything.

<?php

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID().") or die(mysql_error())");    

$arr_uemail = mysql_fetch_array($data);

while($arr_uemail = mysql_fetch_array($data)) 
{
echo $arr_uemail['email'];
}

/*For Debugging purposes
echo $usersClass->userID();*/

?>

Can anybody see anything wrong with my syntax?

There are a lot of errors.

The first is

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID()) or die(whoops);

The second you shouldn't call mysql_fetch_assoc before while, because if the result contains only 1 Record it would never enter in the while

The final code is:

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID()) or die('whoops');

while($arr_uemail = mysql_fetch_array($curr_uemail)) {
echo $arr_uemail['email'];
}

As stated by marc if you have only one records than this could become:

$curr_uemail = mysql_query("select * from [etc]") or die('whoops');    
$arr_uemail = mysql_fetch_array($curr_uemail);
echo $arr_uemail['email'];

I told you the first error via my comment. But please enable error handling and do what the interpreter will tell you.

error_reporting(E_ALL);
ini_set('display_errors', 1);

What also can be erroneous, is this statement here:

while($arr_uemail = mysql_fetch_array($data)) 

You should enclose it with parentheses or the interpreter may warn you.

while(($arr_uemail = mysql_fetch_array($data))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM