...

View Full Version : MySQL Searching



niko
05-19-2004, 12:22 PM
Im creating a recordset filters on orderPaymentReceived,
The code below works fine.

However i need to replace the "y" with a varible, $source which will hold with y or n.

$result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = 'y'");

//---------------------------------------------------
My previous attempt
$result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = ". $source);

Dosnt work.

LynxGrr
05-19-2004, 12:59 PM
Try this

$result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = `". $source."`);

raf
05-19-2004, 01:22 PM
Try this

$result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = `". $source."`);
Welcome here LynxGrr !

Why backticks? + you need to close the double quotes at the end

$result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = '". $source."'");

Niko : never use * --> always specify the columns you need + you need to add some errorhandling. So your codeshould look like:

$result = mysql_query("SELECT var1, var2, var3 FROM tblOrders WHERE orderPaymentReceived = '". $source."'") or die ('Queryproblem when selecting orderdetails');

(replace italics with your columnnames)

LynxGrr
05-19-2004, 01:33 PM
Ive used backticks since i started, makes it easier to see against a " and Ive had no probs with it!

As for the closing "..... whoops! :eek: my bad!

raf
05-19-2004, 02:23 PM
Ive used backticks since i started, makes it easier to see against a " and Ive had no probs with it!
Backticks are for escaping columnnames/tablenames/dbnames that are, for instance, reserved words. To me (and probably other coders), it looks very confusing, because i expect a table/columnname between them and i was initially thinking it was a generic query
(as inside a "where table1.var1=`table2.order`" )

It's maybe unlikly but if you ever get a value like 'blabla.bla' or maybe less unlikely '23333.567' then i would expect your query to error out



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum