Re: [php] if $sql has returned something

From: Date: Wed, 25 Feb 2004 18:26:41 +0000
Subject: Re: [php] if $sql has returned something
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-178872@lists.php.net to get a copy of this message
Richard, Thanks. Should I still include the die ? $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $eventid = $link_date; $sql = 'SELECT * FROM '.$table.' where eventid like \''.$eventid.'\';'; $glquery = mysql_query($sql) or die("Invalid query: " . mysql_error()); $num_rows = mysql_num_rows($glquery); if ($num_rows > 0) { echo "<td width=100 height=100 align=left valign=top><a href=results.php?eventid=$link_date> $day </a></td>"; }else{ echo "<td width=100 height=100 align=left valign=top> $day </td>"; } Richard Davey wrote: > mysql_query will return FALSE if the query is invalid. > If the query is perfectly valid SQL, but just doesn't return > anything, then you need to use mysql_num_rows() instead - if this is > equal to nothing then nothing was returned.

« previous php.general (#178872) next »