PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
imperium2335
Forum Newbie
Posts: 10 Joined: Fri Mar 20, 2009 9:24 pm
Post
by imperium2335 » Sun Mar 22, 2009 12:09 am
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.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Mar 22, 2009 12:27 am
A blank page or just the word "is"?
imperium2335
Forum Newbie
Posts: 10 Joined: Fri Mar 20, 2009 9:24 pm
Post
by imperium2335 » Sun Mar 22, 2009 12:35 am
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.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Mar 22, 2009 12:37 am
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.
imperium2335
Forum Newbie
Posts: 10 Joined: Fri Mar 20, 2009 9:24 pm
Post
by imperium2335 » Sun Mar 22, 2009 12:40 am
Not sure i understand what you mean, I want it to return whats in the numratings and rating fields that are in my database.
imperium2335
Forum Newbie
Posts: 10 Joined: Fri Mar 20, 2009 9:24 pm
Post
by imperium2335 » Sun Mar 22, 2009 12:41 am
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
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Mar 22, 2009 12:57 am
If you want to count rows then
mysql_num_rows is the function you want.