You are here: Re: MySql count « PHP Programming Language « IT news, forums, messages
Re: MySql count

Posted by Akhenaten on 11/20/06 18:11

Actually fixed it using the following:

$arr = array ("A", "B", "C", "D", "E");
foreach ($arr as $client) {
$query = mysql_query("SELECT * from table where columnA = '$client' ");
$num_rows = mysql_num_rows($query);
echo "$client has $num_rows";
echo '<br>';


Unsure as why but for whatever reason I simply can't get a value using
count <pounding head on keyboard>.



On Nov 20, 11:32 am, Christoph Burschka
<christoph.bursc...@rwth-aachen.de> wrote:
> 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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация