<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1027453" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1027453</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163072</link>
    <description> &lt;p&gt;Thank you for your detailed help!&lt;/p&gt;
 </description>
     <pubDate>Wed, 22 Dec 2004 00:16:31 +0000</pubDate>
 <dc:creator>airoid3000</dc:creator>
 <guid isPermaLink="false">comment 1163072 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163063</link>
    <description> &lt;p&gt;timjpriebe is correct; when using COUNT() you will always get a row returned, becasue even if nothing matched, you will get a count of 0, which is returned as a row. This is why you still got a mysql_num_rows() of 1.&lt;/p&gt;
&lt;p&gt;You can do one of the two methods.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$sql = &amp;quot;SELECT COUNT(*) AS numrows FROM table WHERE id=$id AND field=&amp;#039;checked&amp;#039;)&amp;quot;;&lt;br /&gt;$result = $db-&amp;gt;query($sql);&lt;br /&gt;$row = mysql_fetch_array($result);&lt;br /&gt;$rowsMatching = $row[&amp;#039;numrows&amp;#039;];&lt;/code&gt;&lt;/div&gt;&#039;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$sql = &amp;quot;SELECT id AS numrows FROM table WHERE id=$id AND field=&amp;#039;checked&amp;#039;)&amp;quot;;&lt;br /&gt;$result = $db-&amp;gt;query($sql);&lt;br /&gt;$rowsMatching = mysql_num_rows($result);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Either method, &lt;strong&gt;$rowsMatching&lt;/strong&gt; will be set to the number of matching records.&lt;/p&gt;
&lt;p&gt;Things to note: &lt;/p&gt;
&lt;p&gt;The first method always returns just one piece fo data from the database to php, one record, with one field (the count).&lt;/p&gt;
&lt;p&gt;The second method will return multiple rows to php, depending on how many match. Notice that I reduced how much info is returned by doing &lt;strong&gt;SELECT id &lt;/strong&gt;instead of &lt;strong&gt;SELECT *&lt;/strong&gt; which returns all data. &lt;/p&gt;
&lt;p&gt;The first method is the best method of the two for reducing overhead between SQL server and PHP.&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 20:51:00 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1163063 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163061</link>
    <description> &lt;p&gt;I&#039;m not trying to display what was found so thats not a problem.  So there is no way that I can make it return either 0 for no it wasn&#039;t found or 1 for yes it was found (because there is no possibility for there being more than one found)?  If no, then is there another way I can pull off this affect?&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 19:04:03 +0000</pubDate>
 <dc:creator>airoid3000</dc:creator>
 <guid isPermaLink="false">comment 1163061 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163053</link>
    <description> &lt;p&gt;Simple. Your SQL query already returns the count. So it could be 0, 1, or any number.&lt;/p&gt;
&lt;p&gt;Then, $field is assigned the number of records returned. Well, even if there were 0 records that were checked, the SQL query returned one record with the value 0. Count always returns one &quot;record&quot;, and that record is actually just an int representing the number of records.&lt;/p&gt;
&lt;p&gt;You want to use EITHER count (*) OR  mysql_num_rows(), NOT both.&lt;/p&gt;
&lt;p&gt;You can do a normal query and mysql_num_rows() will tell you the number of records. Or you can do count (*) and the value that is returned will be the number of records. No actual records will be returned at all using count (*).&lt;/p&gt;
&lt;p&gt;Make sense?&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 13:20:52 +0000</pubDate>
 <dc:creator>timjpriebe</dc:creator>
 <guid isPermaLink="false">comment 1163053 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163045</link>
    <description> &lt;p&gt;you can also do Select count(*) as count from table ... or even count(id) as count&lt;/p&gt;
&lt;p&gt;try put songle quotes around $id and is there a space between where and (id ... ?&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 10:46:03 +0000</pubDate>
 <dc:creator>Busy</dc:creator>
 <guid isPermaLink="false">comment 1163045 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163042</link>
    <description> &lt;p&gt;On the same subject, I have another problem.  &lt;/p&gt;
&lt;p&gt;I count table &#039;table&#039; where id=$id and field=&#039;checked&#039;.  &lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;	$sql = &amp;quot;select Count(*) from table where(id=$id AND field=&amp;#039;checked&amp;#039;)&amp;quot;;&lt;br /&gt;	$result = $db-&amp;gt;query($sql);	&lt;br /&gt;	$field = mysql_num_rows($result);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;And for some reason, $field ALWAYS equals 1 (even when the field value is not &#039;checked&#039;)&lt;/p&gt;
&lt;p&gt;Why would this happen?&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 05:40:37 +0000</pubDate>
 <dc:creator>airoid3000</dc:creator>
 <guid isPermaLink="false">comment 1163042 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163038</link>
    <description> &lt;p&gt;Abhishek Reddy.....you&#039;re awesome.&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 04:12:57 +0000</pubDate>
 <dc:creator>airoid3000</dc:creator>
 <guid isPermaLink="false">comment 1163038 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163037</link>
    <description> &lt;p&gt;&lt;a href=&quot;http://dev.mysql.com/doc/mysql/en/Counting_rows.html&quot; class=&quot;bb-url&quot;&gt;http://dev.mysql.com/doc/mysql/en/Counting_rows.html&lt;/a&gt;&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 04:05:30 +0000</pubDate>
 <dc:creator>CptAwesome</dc:creator>
 <guid isPermaLink="false">comment 1163037 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/count#comment-1163036</link>
    <description> &lt;p&gt;You can use &lt;a href=&quot;http://nz.php.net/manual/en/function.mysql-num-rows.php&quot; class=&quot;bb-url&quot;&gt;mysql_num_rows()&lt;/a&gt; to count the number of rows returned by a query. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Tue, 21 Dec 2004 04:00:41 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1163036 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
