Try using mysql_query(); instead of mysql_db_query(); The SQL query is the
first parameter in this function. The second parameter is a pointer
connecting to the mysql server. The pointer is generated by mysql_connect()
and you'll also need to select the database with mysql_select_db(). But
it's the standard way..
$db = mysql_connect("localhost", "username", "password"); // connect to
mysql server
mysql_select_db("mytable", $db);
// select database by name
$query = "SELECT * FROM mytable ORDER BY id"; // define query to
submit
$result = mysql_query($query, $db); //
submit query
if (mysql_num_rows($result) > 0)
// skip if no rows were found
{
while ($row = mysql_fetch_array($result))
{
// .. do whtever..
}
}
mysql_close($db);
It's also a common practice to put the first couple of lines in a file to
include() back into your main script so that you can protect your useranme
and password.
Good luck.
-Kevin
----- Original Message -----
From: "Matthew Bielecki" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 24, 2002 10:34 AM
Subject: [PHP] Help with msql_fetch_array()
> I have a couple of scripts that fail with the error of:
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result
> resource in...
>
> I'm new to both SQL and PHP and I'm wondering if I have some setting
> turned off or what.
>
> Here's the piece of code that is failing (the second line fails):
>
> $result = mysql_db_query($dbname, "SELECT * FROM tablename ORDER BY id");
> $row = mysql_fetch_array($result);
>
>
> Thanks for your help in advance!!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php