pak4eva Posted March 29, 2007 Share Posted March 29, 2007 Hi guys Ive managed to connect my sql database using php but the problem im coming across is outputing a message if something equals to null, i.e. i have an attribute in the database called 'Imagename1' so what i want to do is print out a message saying 'no image exist' Imagename1 = 'NULL' ...... output message 'no image exist'. The code im using is below, your help will be very much appreciated.... <?php $host ="?"; $user = "?"; $pass = "?"; $db= "?"; // Connects to your Database $connection = mysql_connect("$host", "$user", "$pass") or die("Unable to connect"); mysql_select_db("$db") or die("Unable to select database"); <?php {$query = "Select Imagename1, Imagename2 From Element Where Symbol ='$_GET'"; IF (Imagename1 = "NULL") { echo("No image available"); } } $result = mysql_query($query) or die ("error in Query: $query. " .mysql_error()); if (mysql_num_rows($result)>0) { echo "<table border=0 cellpadding=0 cellspacing=0>"; while($row= mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $row[0]. "</td>"; echo "<td>" . ' '. "</td>"; echo "<td>" . $row[1]. "</td>"; echo "</tr>"; } echo "</table>"; } else { echo "No rows found"; } ?> Link to comment https://forums.phpfreaks.com/topic/44769-help-with-sql-php/ Share on other sites More sharing options...
mgs019 Posted March 30, 2007 Share Posted March 30, 2007 Hi, One comment is that I think you should use the comparison operator == not the assignment operator =. I tend to use if(str_len($whatever)<1){} because I have had funny results with == null and isset() Martin Link to comment https://forums.phpfreaks.com/topic/44769-help-with-sql-php/#findComment-218140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.