|
-
Feb 4th, 2005, 09:14 AM
#1
Thread Starter
PowerPoster
Simple news script
PHP Code:
$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?
Last edited by Pino; Feb 4th, 2005 at 10:50 AM.
-
Feb 4th, 2005, 09:44 AM
#2
Thread Starter
PowerPoster
Re: Simple news script
And i get the same error for this code
PHP 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
-
Feb 4th, 2005, 10:50 AM
#3
Thread Starter
PowerPoster
Re: Simple news script
Arghhhhhhh
It was because it should be tblNews and not tblnews thats took me all day that has lol :-/
-
Feb 14th, 2005, 03:46 PM
#4
Stuck in the 80s
Re: Simple news script
Remember:
PHP Code:
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|