Results 1 to 4 of 4

Thread: Simple news script

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Resolved 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.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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 

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Simple news script

    Arghhhhhhh

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

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width