PDA

Click to See Complete Forum and Search --> : Simple news script


Pino
Feb 4th, 2005, 08:14 AM
$host="localhost";
$user="me";
$password="you";
$database="hello";


$connection = mysql_connect($host,$user,$password)or die ("Error Conecting To DB");
$db = mysql_selectdb($database,$connection) or die ("bad table\db data");

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

$nrows = mysql_num_rows($result);

for ($i=0;$i<$nrows;$i++)
{
$row = mysql_fetch_array($result);
echo $row;
}


?>

and the error i am getting is

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in path/index.php on line 15

Any ideas on how to fix this?

also if i just wanted to select 3 coloums from the db how would i put my query


$query = "SELECT one two three FROM tblnews"; would that be right?

Pino
Feb 4th, 2005, 08:44 AM
And i get the same error for this code


$connection = mysql_connect($dbhost, $dbusername, $dbpassword);

$query = "SELECT MAX(id) FROM tblnews";
$result = mysql_db_query($database, $query);
$count = mysql_fetch_array($result,MYSQL_ASSOC);

echo $count

Pino
Feb 4th, 2005, 09:50 AM
Arghhhhhhh

It was because it should be tblNews and not tblnews thats took me all day that has lol :-/

The Hobo
Feb 14th, 2005, 02:46 PM
Remember:

or die(mysql_error())

Is your friend. Putting that after mysql_ functions will help get you more specific errors. Such as, putting it after mysql_query() would've told you straight up that the table didn't exist.

Just a heads up.