Results 1 to 4 of 4

Thread: display empty count result

  1. #1
    Join Date
    Sep 2009
    Posts
    48
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question display empty count result

    Hi

    i have this code..how do i display empty count result ?
    Code:
    <?php
    // Make a MySQL Connection
    
    $query = "SELECT type, COUNT(name) FROM products GROUP BY type"; 
    	 
    $result = mysql_query($query) or die(mysql_error());
    
    // Print out result
    while($row = mysql_fetch_array($result)){
    	echo "There are ". $row['COUNT(name)'] ." ". $row['type'] ." items.";
    	echo "<br />";
    }
    ?>

  2. #2
    Join Date
    Dec 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <?php
    // Make a MySQL Connection
    
    $query = "SELECT type, COUNT(name) as count FROM products GROUP BY type"; 
    	 
    $result = mysql_query($query) or die(mysql_error());
    
    // Print out result
    while($row = mysql_fetch_array($result)){
    	echo "There are ". $row['count'] ." ". $row['type'] ." items.";
    	echo "<br />";
    }

  3. #3
    Join Date
    Dec 2014
    Location
    Hanoi, Vietnam
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jan127 View Post
    Code:
    <?php
    // Make a MySQL Connection
    
    $query = "SELECT type, COUNT(name) as count FROM products GROUP BY type"; 
    	 
    $result = mysql_query($query) or die(mysql_error());
    
    // Print out result
    while($row = mysql_fetch_array($result)){
    	echo "There are ". $row['count'] ." ". $row['type'] ." items.";
    	echo "<br />";
    }
    it's ok, thanks jan127

  4. #4
    Join Date
    Dec 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Using this code you can display empty count result:
    Code:
    $total_rows = mysql_num_rows($result);
    if($total_rows>0){
    // please use your code in this section 
    
    
    }
    <?php
    // Make a MySQL Connection
    
    $query = "SELECT type, COUNT(name) FROM products GROUP BY type"; 
      
    $result = mysql_query($query) or die(mysql_error());
    $total_rows = mysql_num_rows($result);
    if($total_rows>0){
    // Print out result
    while($row = mysql_fetch_array($result)){
     echo "There are ". $row['COUNT(name)'] ." ". $row['type'] ." items.";
     echo "<br />";
    }
    }
    
    ?>
    Last edited by james438; 12-16-2014 at 07:10 PM.

Similar Threads

  1. Jason's Date Input Calendar - Need Help to Display Empty Date Fields?
    By Dorgs in forum Dynamic Drive scripts help
    Replies: 9
    Last Post: 06-07-2013, 02:08 PM
  2. display search result on my site
    By mavtrevor in forum Looking for such a script or service
    Replies: 9
    Last Post: 08-20-2011, 08:52 PM
  3. Resolved Joining result of multiple selects to get final result?
    By gwmbox in forum JavaScript
    Replies: 2
    Last Post: 01-04-2011, 01:18 PM
  4. Replies: 5
    Last Post: 12-30-2008, 08:52 AM
  5. Using COUNT To Display Results
    By tomyknoker in forum PHP
    Replies: 0
    Last Post: 08-23-2007, 01:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •