PDA

View Full Version : Resource id#2


Switch17
07-14-2003, 03:53 AM
I just picked up a mysql book, and am beginning to learn some basics, but already seem to be struggling.

I have a table that I'm just trying to get to show up in a webpage. This is all thats in the file.
$user="xxxxxxx";
$host="localhost";
$password="xxxxxx";
mysql_connect($host,$user,$password);
mysql_select_db("xxxxx);

$query = "SELECT * FROM nfl_teams";
$result = mysql_query($query);

echo $result;
And All I ever get to show up is this:

Resource id #2

Can anyone help out a newbie in understanding all of this?

Switch17
07-14-2003, 04:14 AM
OK, I just learned via a google search that I needed to add the

$myrow = mysql_fetch_array($result);

to it. But I seem to only retrieve one row only. How do I show the whole table?

raf
07-14-2003, 08:37 AM
It's more of a PHP problem. To make faster proces, i think you should bet look for a tutorial on PHP (if you run a earch in the PHP forum or on google, plenty of tutorials will turn up)

About your problem. $result will be nothing more then a reource id --> sort of reference to the recordset. So you need mysql_fetch_array($result)to display the actual values for the record where the resource id points to.

But, you need to loop through the recordet to proces all record. Like

while($row=mysql_fetch_array($result)){
echo $row['name'];
}

while($row=mysql_fetch_array($result)) --> will loop through the complete recordet, until the last record was processed. All statements wetween the bracket wil be executed for each record.
echo $row['name']means 'print the value of variabel 'name' for that row.
More info:
http://be.php.net/manual/en/function.mysql-fetch-array.php
Tutorial i'd recommend reading to get the basics of MySQL and PHP: http://www.sitepoint.com/article/228/2