PHP/MYSQL Question

Discussion in 'PHP' started by designcentral, Aug 2, 2009.

  1. #1
    Hi there,

    My code:
      include 'database_connect.php';
    $query="SELECT * FROM auctions WHERE status = 'Payment Received'";
    $result=mysql_query($query);
    
    $num=mysql_numrows($result);
    
    mysql_close();
    
    $i=0;
    while ($i < $num) {
    
    include 'view_layout.php;
    PHP:
    I would like to know how I can echo "No items where payment is received." when there are no table entries WHERE status ='Payment Received'

    Any help would be appreciated.

    Thanks
     
    designcentral, Aug 2, 2009 IP
  2. rldowling03

    rldowling03 Notable Member

    Messages:
    1,763
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Try this, if you want to not exit the script straight after then you will need to add a else{} after then and of that if statement, I cant show that as that code seems to be incomplete

    
    include 'database_connect.php';
    $query="SELECT * FROM auctions WHERE status = 'Payment Received'";
    $result=mysql_query($query);
    
    $num=mysql_numrows($result);
    
    if($num==0){
    echo "No items where payment is received.";
    exit();
    }
    
    mysql_close();
    
    $i=0;
    while ($i < $num) {
    
    include 'view_layout.php; 
    
    PHP:
     
    rldowling03, Aug 2, 2009 IP
  3. XDMCoder

    XDMCoder Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    include 'database_connect.php';
    $query="SELECT * FROM auctions WHERE status = 'Payment Received'";
    $result=mysql_query($query);
    
    $num=mysql_numrows($result);
    
    mysql_close();
    
    if($num<1)
    {
    	echo "No items where payment is received.";
    }
    else
    {
    	$i=0;
    	while ($i < $num)
    	{
    		include "view_layout.php"; // mby $i++?
    	}
    }
    ?>
    PHP:
     
    XDMCoder, Aug 2, 2009 IP
  4. designcentral

    designcentral Guest

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Cheers guys, I had an if statement previously but I had it in the wrong place. Cheers!
     
    designcentral, Aug 2, 2009 IP