Re: query returned "Resource id #2" (quick php/mysql tutorial)
| From: | Jonathan Hilgeman | Date: | Fri, 17 Aug 2001 21:19:11 +0000 |
| Subject: | Re: query returned "Resource id #2" (quick php/mysql tutorial) | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11485@lists.php.net to get a copy of this message | ||
Hi Alex,
mySQL doesn't return normal PHP values. You need to use mysql functions to
convert the mySQL resulting data into an array, like so:
// mySQL Table:
// --------------------------------
// field1 | field2 | stuff |
// --------------------------------
// Florida | Ferrari | George |
// --------------------------------
// Detroit | Honda | Raymond |
// --------------------------------
// Kansas | Porsche | Betsy |
// --------------------------------
$Link = mysql_connect("server","username","password");
$Query = "SELECT field2,stuff FROM table;";
$Result = mysql_db_query("database",$Query,$Link);
while($ResultRow = mysql_fetch_array($Result))
{
// Now we're in a loop that cycles 3 times (there are 3 records)
// The first time, $ResultRow will be an array that looks like:
// $ResultRow["field2"] => "Ferrari"
// $ResultRow["stuff"] => "George"
// The next cycle through the loop, $ResultRow will look like:
// $ResultRow["field2"] => "Honda"
// $ResultRow["stuff"] => "Raymond"
// The last cycle through the loop, $ResultRow will be:
// $ResultRow["field2"] => "Porsche"
// $ResultRow["stuff"] => "Betsy"
print $ResultRow["stuff"] . " owns a " . $ResultRow["field2"] .
"<BR>";
}
// The above script will write the following to your screen:
// George owns a Ferrari
// Raymond owns a Honda
// Betsy owns a Porsche
Hope this helps.
- Jonathan
"Default" <test@ancbt.org> wrote in message
news:20010817210215.82942.qmail@pb1.pair.com...
> Hi,
>
> I'm using PHP 4 and mysql. I'm trying to do just a simple query from a
> database table, but every time it returns the value, it returns
> "Resource id #2" and results like that. Any ideas? Thanks.
>
> Alex
>