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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question if & else problem

    hi,i hav a problem here...

    if lets say i hav a query:
    Code:
    $query1= "select count(*) AS i from tblpatient";
    then i wan to count how many records there:
    Code:
    <?php if ($row1["i"] >= 1){ ?>
    <tr>
    -----
    </tr>
    
    <?php }else {?>
    	<tr>
    	<td height="60" colspan="16"><center>NO RECORDS</center></td>
    	</tr>
    	
    	<?php }?>
    but it still cannot show NO RECORDS whenever there is no record...
    izzit if ($row1["i"] >= 1){ sth wrong?????

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The code you posted looks ok, so the problem must be in the code you didn't post-- the "fetch" statement, etc.

  • #3
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by tanhaha_how View Post
    then i wan to count how many records there:
    PHP Code:
    <?php if ([COLOR="DarkRed"]$row1["i"] >= 1[/COLOR]){ ?>
    <tr>
    -----
    </tr>

    <?php }else {?>
        <tr>
        <td height="60" colspan="16"><center>NO RECORDS</center></td>
        </tr>
        
        <?php }?>
    Easiest way to count how many rows were retrieved is to use mysql_num_rows(), like so:

    PHP Code:
    $query1"select count(*) AS i from tblpatient";

    $count mysql_num_rows($query1);

    if (
    $count 1) {
       
    //echo "no rows were found"
    } else {
       
    //echo the rows that were found



  •  

    Posting Permissions

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