|
Posted by Christoph Burschka on 11/20/06 17:32
Akhenaten wrote:
> The following snippet (for whatever reason) returns no value for the
> count. Suggestions?
>
>
> $arr = array ("A", "B", "C", "D", "E");
> foreach ($arr as $client) {
> $count = mysql_query('SELECT COUNT(*) from table where columnA =
> $client');
> echo "$client has $count";
> echo '<br>';
> }
>
1. You can't pass variables within single quotes.
Instead of '... $client' you either need "... $client" or '... '.$client
2. Strings in MySQL queries need to be surrounded by quotes (either single or
double).
This will work:
"SELECT COUNT(*) from table where columnA = '$client'"
as will this:
'SELECT COUNT(*) from table where columnA = "'.$client.'"'
--
Christoph Burschka
Navigation:
[Reply to this message]
|