Jump to content

null result


googlit

Recommended Posts

hi all,

 

i have a script in where the user enters there post code and it will provide a price for delivery, how would i echo "please contact us for price" if the db record for the price is (null) or empty??

 

<?php
mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("postcode");
$term = $_POST['term'];
$sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large ");
while ($row = mysql_fetch_array($sql)){
    echo '<br/> Postcode: '.$row['postcode'];
    echo '<br/> Town: '.$row['town'];
    echo '<br/> County: '.$row['county'];
    echo '<br/> Small: £'.$row['price_s'];
    echo '<br/> Medium: £'.$row['price_m'];
    echo '<br/> Large: £'.$row['price_l'];
    echo '<br/><br/>';
    }
    
?>

Link to comment
https://forums.phpfreaks.com/topic/214003-null-result/
Share on other sites

<?php
mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("postcode");
$term = $_POST['term'];
if ($sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large ")) {
  if (mysql_num_rows($sql)) {
    while ($row = mysql_fetch_array($sql)){
      echo '<br/> Postcode: '.$row['postcode'];
      echo '<br/> Town: '.$row['town'];
      echo '<br/> County: '.$row['county'];
      echo '<br/> Small: £'.$row['price_s'];
      echo '<br/> Medium: £'.$row['price_m'];
      echo '<br/> Large: £'.$row['price_l'];
      echo '<br/><br/>';
    }
  } else {
    echo "please contact us for price";
  }
}    
?>

Link to comment
https://forums.phpfreaks.com/topic/214003-null-result/#findComment-1113688
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.