Page 1 of 1

Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:09 am
by imperium2335
Hi, I'm trying to retrieve the information from my table but it returns a blank page.

image_id is the primary key in the table and is set to auto increment, is this why i cant retrieve the info? Ive retrieved info from other fields with no problems.

Code: Select all

<?PHP
 
if (!file_exists("../dbconnect.php"))
{
    die("Database settings not found, administrator intervention required.") ;
}
else
{
    require("../dbconnect.php") ; //Must connect to the database.
}
 
//$userrate = $_GET['rating'] ;
$currentimage = 5 ;//$_SESSION['currentimage'] ;
 
$query = "SELECT image_id FROM image_bank WHERE image_id = '$currentimage'" ;
 
$result = mysql_query($query) ;
 
$nrows = mysql_fetch_row($result) ;
 
while($row = mysql_fetch_array($result))
{
 
    $currentrating = $row['rating'] ;
    $numratings = $row['numratings'] ;
    
echo "is $currentrating $numratings" ;
 
}
?>
Thanks in advance.

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:27 am
by requinix
A blank page or just the word "is"?

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:35 am
by imperium2335
the word is, sorry.

Ive echoed the query and it shows SELECT * FROM image_bank WHERE image_id = 5 which is correct i think.

Thanks.

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:37 am
by requinix
The query is only supposed to return one row, right?

Code: Select all

$nrows = mysql_fetch_row($result);
 
while($row = mysql_fetch_array($result))
In the first line you fetch the row. The only row. There's nothing left to get after that.

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:40 am
by imperium2335
Not sure i understand what you mean, I want it to return whats in the numratings and rating fields that are in my database.

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:41 am
by imperium2335
never mind, i deleted that line and it works now lol thanks. Actually i was kinda dumb, why try count rows when i know only one will be retrieved lol :P

Re: Primary key field wont retrieve

Posted: Sun Mar 22, 2009 12:57 am
by requinix
If you want to count rows then mysql_num_rows is the function you want.