0

I would like to make some query using the SELECT function. However i wasnt able to get the results i want.
My code is as follow:

$sql = "SELECT *
FROM device 
WHERE ((device_num like '%$val_d%') OR (dib like '%$val_dp%')) ";

can i write it in this way? pls advise thanks people..:)

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by network18
0

Try replacing it with the following:

$sql = 'SELECT * FROM device WHERE `device_num` LIKE "'.mysql_real_escape_string($val_d).'" OR `dib` LIKE "'.mysql_real_escape_string($val_dp).'"';
0

If you want wildcards then the following contains the wildcards:

$sql = 'SELECT * FROM device WHERE `device_num` LIKE "%'.mysql_real_escape_string($val_d).'%" OR `dib` LIKE "%'.mysql_real_escape_string($val_dp).'%"';
0

I would like to make some query using the SELECT function. However i wasnt able to get the results i want.
My code is as follow:

$sql = "SELECT *
FROM device 
WHERE ((device_num like '%$val_d%') OR (dib like '%$val_dp%')) ";

can i write it in this way? pls advise thanks people..:)

in first place check whether $val_d and $val_dp variables are set when this query is formed, otherwise your query may get executed like -

$sql = "SELECT * FROM device WHERE ((device_num like '') OR (dib like '')) ";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.