Jump to content

help with sql + php


pak4eva

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.