PDA

View Full Version : can not make the row count work



ketanco
05 Oct 2008, 05:02 PM
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;

?>

Agrunyan
05 Oct 2008, 06:47 PM
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).



<?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