If Check Value of Field

Hi all, just a quick one, I’m trying to check what the value is in a field in my database, if it’s 0.00 then I don’t want it to execute. If however it’s something such as 200.00 then I want it to go ahead and execute.

$partx = mysql_query("SELECT part_exchange FROM orders WHERE receipt_id='$_GET[ref]'");
if (!$res = mysql_fetch_array($partx['part_exchange'])==0.00){
echo 'Hello World :)';

P.S I have a connection to my DB already above this syntax.

$partx = mysql_query("SELECT part_exchange FROM orders WHERE receipt_id='$_GET[ref]' AND part_exchange > 0"); 

Now you got everything that is more than 0, which is what you should do. You filter the data-set with SQL, not with PHP.

Also, clean your input, anyone can drop your database or delete everything from any table if they want to.

Hey furicane, sure thing, I will drop a mysql_real_escape_string in. I think that should secure things slightly. Thank you for your help, massive help! :slight_smile:

Hey dude, I still can’t seem to get what I’m wanting. Basically it’s for part exchange. If the field value is 0.00 then leave page as it is. If however it’s more than 0.00 then I want some text to show, hence why I’m using an if statement.

$sql = sprintf(
  "SELECT part FROM table WHERE ref = '%s' AND value > 0 LIMIT 1;",

$res = mysql_query($sql);

if(1 === mysql_num_rows($res)){
  #row found

Brilliant one Anthony, all working swimmingly now! :smiley: Cheers dude, appreciate it.