0

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?

3
  • 4
    what is this? ") or die(whoops)"); didn't you notice the strange highlighting? x) Commented May 31, 2011 at 21:05
  • haha sorry I didnt, either way with that fixed it's still not working Commented May 31, 2011 at 21:06
  • so update your code. the other code should work. Commented May 31, 2011 at 21:07

2 Answers 2

1

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'];
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry I've amended my original question.
that's because you should do mysql_fetch_array($curr_uemail) and not $data And I have edited my answer
Assuming that produgg_users.id is a PK field, the query could only ever produce once record at most, so the while loop is useless. a single fetch call would take care of things.
0

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))) 

2 Comments

The extra brackets are useless. Omitting them does not cause a warning/error.
No, it may cause a warning, see: stackoverflow.com/questions/718415/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.