0

I'm a beginner PHP programmer, so sorry if I'm asking some silly question. I've set up a MySQL database with a table carrying a list of boolean values. I want the PHP page count the number of 'true' on a column (from the table) and display it as a single number. Eg, if there is 4 'true's on the column, it display '4'. How do I do it?

I've tried to start it off, but it's displaying something wired - 'Resource id #4', which I have no idea what it is. Here is my code -

<?php
	include("conmysql.php");
    $selectdb = @mysql_select_db("vote");
    if (!$selectdb) die("Connect database fail!");
    
    //find number of people supporting
    $sql = 'SELECT COUNT(support) FROM address WHERE support=1';
	$result = mysql_query($sql);
	if (!result) {
		die('Invalid query: ' . mysql_error());
	}	
	echo "$result";
?>

CAN SOMEONE HELP!!

If you want to look at my real example, here is the page on my server - http://vernmedia.dyndns.org/.

Thanks

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by TechySafi
0

Let's see if it works...

$count=mysql_num_rows($result);
if (!result) {
		die('Invalid query: ' . mysql_error());
	}	
echo $count; //not $result
0

I agree.

<?php include("conmysql.php");
    $selectdb = @mysql_select_db("vote");
    if (!$selectdb) die("Connect database fail!");
    //find number of people supporting
    $sql = 'SELECT COUNT(support) FROM address WHERE support=1';
	$result = mysql_query($sql);
        $count=mysql_num_rows($result);
        if (!result) {
	    die('Invalid query: ' . mysql_error());
	}	
    echo $count; //not $result
?>
0

Cool :) So mark this thread as solved now!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.