Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Is table empty?

  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts

    Is table empty?

    Hi I have a MySQL database and a script that get data from a table

    PHP Code:
    <?PHP
            $query 
    sprintf("SELECT * FROM courses",
        
    mysql_real_escape_string($code));
        
    $result mysql_query($query);
        while (
    $row mysql_fetch_assoc($result))
        {
            
    $index=$row['code'];
            
    $stack[$index]['title']=$row['title'];
            
    $stack[$index]['description']=$row['description'];
            
    $stack[$index]['level']=$row['level'];
            
    $stack[$index]['code']=$row['code'];
            
    $stack[$index]['active']=$row['active'];
        }
    ?>
    This works fine. What I need to be able to do is have the script tell me if the table was empty so I don't attempt to render an empty html representation. Is this possible without the aid of an additional query?
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,005
    Thanks
    58
    Thanked 10 Times in 10 Posts

    Cool

    PHP Code:
    [CODE]
            
    $query sprintf("SELECT * FROM courses",
        
    mysql_real_escape_string($code));
        
    $result mysql_query($query);
    $numrows mysql_num_rows($result )or die("Error retrieving number of rows in groups table.");


    if(
    $numrows 0) {

    while (
    $row mysql_fetch_assoc($result))
        {
            
    $index=$row['code'];
            
    $stack[$index]['title']=$row['title'];
            
    $stack[$index]['description']=$row['description'];
            
    $stack[$index]['level']=$row['level'];
            
    $stack[$index]['code']=$row['code'];
            
    $stack[$index]['active']=$row['active'];
        }
    }
    [/
    CODE
    hope this helps


  • Users who have thanked nikos101 for this post:

    timgolding (11-13-2007)


  •  

    Posting Permissions

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