Results 1 to 2 of 2

Thread: can not make the row count work

  1. #1
    Join Date
    Oct 2007
    Posts
    103

    can not make the row count work

    I know it is simple but can not figure out why i can not count the rows in my mysql table, (called answers1)...This only gives an output of : Resource id #2

    I dont understand what that means, nor it gives me any count result...

    <?php
    //Connect To Database
    $hostname=xxxxxxxxxx;
    $username=xxxxxxxxxx;
    $password=xxxxxxxxxx;
    $dbname=xxxxxxxxxxxx;


    mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_db($dbname);

    $query=" select count(response) FROM answers1";
    //I also tried $query="count(*) FROM answers1";

    $total=mysql_query($query);


    echo"</br>";
    echo"</br>";

    echo $total;

    ?>

  2. #2
    I am by no means an expert in PHP but try cleaning up your code some, this is what it should look like (I have not tested it).

    Code:
    <?php
     //Connect To Database
     $hostname = 'xxxxxxxxxx';
     $username = 'xxxxxxxxxx';
     $password = 'xxxxxxxxxx';
     $dbname   = 'xxxxxxxxxx';
     
     
     mysql_connect('$hostname','$username','$password') OR DIE ('Unable to connect to database! Please try again later.');
     mysql_select_db($dbname);
     
     $query = 'SELECT count(response) FROM answers1";
     //I also tried $query="count(*) FROM answers1";
     
     $total = 'mysql_query($query)';
     
     
     echo '</br>';
     echo '</br>';
     
     echo $total;
     
     ?>
    Alex

Similar Threads

  1. Two methods make our webpage design work more easy
    By abelz22 in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 08 Jun 2006, 10:36 PM

Posting Permissions

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