"News.Php.Net" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> To help me learn using these awesome tools together, I'm creating a sample
> application for myself - a movie database.  In this database (which is
named
> "movies"), I have five tables.  One named "moviemain", one named "actors",
> one named "genre", and then two tables that are designed to link these
> tables together "moviegenre" and "movieactor".  I've created a MySQL query
> to get all records, and it works great if I use it directly with MySQL,
> however every time I try it with PHP it gives me a "Resource id #2"
message.
> It seems to have something to do with creating a user connection twice, or
> something liek that, but I'm not sure.  Here's the simple code snippet:
>
> <?php
> $dbcxn = @mysql_connect('localhost','root','');
>   if (!$dbcxn) {
>     echo('<p>Unable to connect to the database at this time</p>');
>     exit();
>  }
> mysql_select_db('movies',$dbcxn);
>   if (! @mysql_select_db('movies') ) {
>     die('<p>Unable to locate the Movie database within the database
> server</p>');
>  }
> $result = @mysql_query("SELECT * from
> MovieMain,movieactor,moviegenre,genre,actors where
> MovieMain.movieid=movieactor.movieid and
> MovieMain.movieid=moviegenre.movieid and genre.genreid=moviegenre.genreid
> and actors.actorid=movieactor.actorid");
> if (!$result) {
>   die('<p>Error performing query: ' . mysql_error() .  '</p>');
>   }
> echo $result;
> ?>

$result is a MySQL result resource handle, you cannot just echo it out. You
have to use a loop to iterate through every row of the result. Try this:

while ($row = mysql_fetch_assoc($result)) {
    // now you have an array with all field values of the current record, do
a print_r($row) to see how the array is structured
}

See here:
http://de.php.net/mysql_fetch_assoc

Regards, Torsten

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to