if No Records show me!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jbdphp
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 4:53 pm

if No Records show me!

Post by jbdphp »

Hello having trouble with a simple script. I can get the data out perfect but I need it to display "No Records" if there are no records in the query. Here is my code, I am sorry if it's sloppy! Thanks in advance!

Code: Select all

<?php

//******* this is part of a script so assume I already connected to my db


$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");
							

				//******************* here is my problem!!!!!
				
				$row = mysql_fetch_row($showzsql);
  
  if($row = 0) {
							   echo "no records!"; 

  } else {

	//*********************************************************
	
	while($x=mysql_fetch_array($showzsql)) {
								
						
								$sid = $xї"sid"];
								$show_date = $xї"show_date"];
								$venue = $xї"venue"];
							  
								
					 echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";

							}

?>
<? } ?>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?

$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC"); 
             
            $row = mysql_num_rows($showzsql); 
   
  if($row = 0) { 
                        echo "no records!";  

  } else { 
    
   while($x= mysql_fetch_array($showzsql)) { 
                         
                   
                        $sid = $xї"sid"]; 
                        $show_date = $xї"show_date"]; 
                        $venue = $xї"venue"]; 
                        
                         
                echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>"; 

                     } 
}

?>
User avatar
jbdphp
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 4:53 pm

close but...

Post by jbdphp »

It still doesn't print "no records!" Any other suggestions?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

use hob_goblin's code but change

Code: Select all

if($row = 0)
to

Code: Select all

if($row == 0)
your code will skip the first record
Last edited by volka on Mon Sep 02, 2002 7:44 pm, edited 1 time in total.
User avatar
jbdphp
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 4:53 pm

Post by jbdphp »

volka wrote:change

Code: Select all

if($row = 0)
to

Code: Select all

if($row == 0)
:D :D :D THANK YOU!!!!!!!!!!!!!!!!!!!!! :D :D :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

merde, I was too slow altering my post :?
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

make:

Code: Select all

<?php 

//******* this is part of a script so assume I already connected to my db 


$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC"); 
                      

            //******************* here is my problem!!!!! 
             
            $row = mysql_fetch_row($showzsql);
            $rowcount = mysql_num_rows($row);
   
  if($rowcount == '0') { 
                        echo "no records!";  
  } else { 

   //********************************************************* 
    
   while($x=mysql_fetch_array($showzsql)) { 
                         
                   
                        $sid = $xї"sid"]; 
                        $show_date = $xї"show_date"]; 
                        $venue = $xї"venue"]; 
                        
                         
                echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>"; 

                     } 

?> 
<? } ?>
this:

Code: Select all

<?php
<?php 

//******* this is part of a script so assume I already connected to my db 


$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC"); 
                      

            //******************* here is my problem!!!!! 
             
            $row = mysql_fetch_row($showzsql); 
   
  if($row = 0) { 
                        echo "no records!";  

  } else { 

   //********************************************************* 
    
   while($x=mysql_fetch_array($showzsql)) { 
                         
                   
                        $sid = $xї"sid"]; 
                        $show_date = $xї"show_date"]; 
                        $venue = $xї"venue"]; 
                        
                         
                echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>"; 

                     } 
}
?>
?>
later on, -Brian
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

almost :wink:
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

SCRATH that last post...messed it up...THIS:

make this:

Code: Select all

<?php
//******* this is part of a script so assume I already connected to my db 


$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");  
                       

            //******************* here is my problem!!!!! 
              
            $row = mysql_fetch_row($showzsql);  
    
  if($row = 0) {  
                        echo "no records!";   

  } else {  

   //********************************************************* 
     
   while($x=mysql_fetch_array($showzsql)) {  
                          
                    
                        $sid = $xї"sid"];  
                        $show_date = $xї"show_date"];  
                        $venue = $xї"venue"];  
                         
                          
                echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";  

                     }

?>
<? } ?>
this:

Code: Select all

<?php
//******* this is part of a script so assume I already connected to my db 


$showzsql = mysql_query("SELECT * FROM shows WHERE bandaide_band = '$bname' ORDER BY sdfdb ASC");  
                       

            //******************* here is my problem!!!!! 
              
            $row = mysql_fetch_row($showzsql); 
            $rowcount = mysql_num_rows($row); 
    
  if($rowcount == '0') {  
                        echo "no records!";   
  } else {  

   //********************************************************* 
     
   while($x=mysql_fetch_array($showzsql)) {  
                          
                    
                        $sid = $xї"sid"];  
                        $show_date = $xї"show_date"];  
                        $venue = $xї"venue"];  
                         
                          
                echo "<tr align="center"><td>$show_date</td><td>$venue</td><td><a href="index.php?location=showz&sid=$sid">MORE INFO</a></tr>";  

                     }  
}
?>
later on, -Brian
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

h3h3, I know this and when it happens to me I try to be fast enough changing it before someone notices - unfortunately that doesn't work often 8O
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

Hush, Volka. :P I figure, if i think i have it right, move on to another post...don't lniger...and as soon as i saw ur post, I changed it...but sadly it'll take someone else relentlest torrent to make me see it...or an "Almost" :P

later on, -Brian
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

jbdphp, it is better to not use things like $x in your code make it more meaningful, something like $ShowsRecord would better describe what you have returned from the database.
User avatar
jbdphp
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 4:53 pm

Post by jbdphp »

mikeq wrote:jbdphp, it is better to not use things like $x in your code make it more meaningful, something like $ShowsRecord would better describe what you have returned from the database.
Thank you Mike I will keep that in mind.
Post Reply