Hi, i'm trying to select two values from my database.

$nc ='North Carolina';
$t ='Hello';
$q = 'SELECT COUNT(state, title) AS c FROM all WHERE state = "' . mysql_real_escape_string($nc) . '" AND title = "' . mysql_real_escape_string($t) . '"';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);
$count = $fetch['c'];

echo = "$count";

I need it so it will only echo out the number of posts from North Carolona and with the title Hello.
It doesn't echo out nothing.

Hi,

You have a problem at line 8; there is the = operator that shouldn't be. Just remove it and it will be fine.

It still doesn't work

It doesn't echo out the number of post.
I think something is wrong in the line 3 but i don't know what it is.

Yes, you're right that is another problem.. I didn't notice.

The SQL function count doesn't take two column names. try to use one column name or 1 or * as an argument for the function like this:

$q = 'SELECT COUNT(state) AS c FROM all WHERE state = "' . mysql_real_escape_string($nc) . '" AND title = "' . mysql_real_escape_string($t) . '"';

Are you supressing the error messages? The interpreter should be giving you the message & line number of the error by default.

Be a part of the DaniWeb community

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