Re: PHP - MySQL Query...

From: Date: Thu, 14 Aug 2003 11:28:12 +0000
Subject: Re: PHP - MySQL Query...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159550@lists.php.net to get a copy of this message
I'm used to do like this: $query = 'SELECT * FROM cities'; $result = mysql_query($query); if($row = mysql_fetch_array($result)) do { echo ('<tr> <td class="city">' . $row[0] . ', ' . $row[1] . '</td> <td>' . $row[2] . '</td> <td>' . $row[3] . "</td> </tr>\n"); } while ($row = mysql_fetch_array($result)); ------------------------------------------------------- "Jay Blanchard" <jay.blanchard@niicommunications.com> wrote in message news:C8F323573C030A448F3E5A2B6FE2070B0101FA81@nemesis... [snip] $dbh = mysql_connect("localhost", "login", "password") or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db("database"); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('<tr> <td class="city">' . $row[0] . ', ' . $row[1] . '</td> <td>' . $row[2] . '</td> <td>' . $row[3] . "</td> </tr>\n"); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? [/snip] mysql_query needs both the query variable and the connection variable.... mysql_query($query, $dbh); HTH!

« previous php.general (#159550) next »