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

Member Avatar for TechySafi

Let's see if it works...

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

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

Many Thanks!!! I've finally got this working!

Member Avatar for TechySafi

Cool :) So mark this thread as solved now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.