if no results returned

Discussion in 'PHP' started by red_fiesta, Apr 26, 2007.

  1. #1
    i have this code

    <?
    
    	    
    		$strSQL = "SELECT * from  seasonsbefore07 WHERE Game_Type='T' and Season=".$season;
    	
    		$Conn=mysql_connect(***);
    		mysql_select_db("sodraupsala",$Conn);
    		$result = mysql_query($strSQL);	
    		
    	 			
    
    ?>								
    							
    						  <table width="500" border="0" cellspacing="0" cellpadding="5" class="customerDetails" summary="This is a data table displaying News items available">
    							  <thead class="customerDetails">
    							  <tr>
    							  <td class="customerDetailsThead" style="width:200px; text-align:left;  padding-left:5px;">Träningsmatch</td>
    							  
    							  <td class="customerDetailsThead" style="width:100px; text-align:left">Resultat</td>
    							  
    
    							  </tr>
    
    							  </thead>  
    						  
    	<? while($row = mysql_fetch_assoc($result)){ ?>								  
    							  <tr>
    							  <td  class="customerDetails" style="padding-left:5px;" <?
    						$match=$row['Match_ID']; 
    						
    						if ( $match == 0 ) {  
    							  
    							  print $row['MatchReq'];
    							   
    							 }
    							 
    							 else { ?>
    							 
    							 
    							 
    							 <A onClick="return popup(this, 'notes')" HREF="../matchreport.php?matchid=<? print $row['Match_ID'] ?>"><? print $row['MatchReq'] ?></a>
    							 
    							 
    							 <? } ?></td>
    							  <td  class="customerDetails"><? print $row['Score'] ?></td>
    							
      </tr>
    						  
    							<? } ?>  
    							  </table>	
      		<?
    	mysql_close($Conn); 
    		    
    	
    	 ?>	
    
    Code (markup):
    I want to make it that is there are no results from the database the table doesnt show. In asp this is a is

    <% if not recordset.eof%>
    Code (markup):
    What is it in php?
     
    red_fiesta, Apr 26, 2007 IP
  2. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #2
    It depends on how you fetch the database.
    If you call mysql_fetch_assoc() then the function will return either the recordset or null.

    You can call mysql_num_rows() and get the number of rows.
    After

    $result = mysql_query($strSQL);	
    PHP:
    call

    if (mysql_num_rows($result) > 0)
    print('I found rows')
    else
    print('recordset EOF') 
    PHP:
     
    weppos, Apr 26, 2007 IP