0

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.

2
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by The Diamonds
0

Hi,

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

Edited by The Diamonds

0

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.

Edited by Cristianh21

0

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.

Edited by The Diamonds

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.