Jump to content

[SOLVED] status='on' function is not working


sungpeng

Recommended Posts

$sql = "SELECT * FROM users WHERE specialise1 LIKE '%$specialise1%' OR specialise2 LIKE '%$specialise1%' OR specialise3 LIKE '%$specialise1%' AND status='on' ORDER BY listdate LIMIT $offset, $rowsperpage";   

 

hi above the  status='on' function is not working, status either "off" or "on" it will display, is there any mistake in the above query? pls help.. Thk

Link to comment
https://forums.phpfreaks.com/topic/159456-solved-statuson-function-is-not-working/
Share on other sites

$sql = "SELECT * FROM users WHERE specialise1 LIKE '%$specialise1%' OR specialise2 LIKE '%$specialise1%' OR specialise3 LIKE '%$specialise1%' AND status='on' ORDER BY listdate LIMIT $offset, $rowsperpage" or die(mysql_error());   

 

Hi jack it still display the record although my status is 'off'. Not 'on'. By right it shouldn't display anything. It did not show any error.

$sql = "SELECT * FROM listings WHERE address LIKE '%$address%' AND type LIKE '%$type%' AND price LIKE '%$price%' ORDER BY listdate LIMIT $offset, $rowsperpage"; 

 

sql = "SELECT * FROM users WHERE specialise1 LIKE '%$specialise1%' OR specialise2 LIKE '%$specialise1%' OR specialise3 LIKE '%$specialise1%' ORDER BY listdate LIMIT $offset, $rowsperpage" or die(mysql_error()); 

 

 

The above 2 codes is working fine. But once "or" "or" "and" conbined together, the "and" part is not working anymore?

 

 

The posted query is AND'ing -

 

specialise3 LIKE '%$specialise1%' AND status='on'

 

Then it is OR'in that with the remainder of the OR terms. To force the AND term to apply to all the OR terms, you need to place () around the OR terms -

 

$sql = "SELECT * FROM users WHERE (specialise1 LIKE '%$specialise1%' OR specialise2 LIKE '%$specialise1%' OR specialise3 LIKE '%$specialise1%') AND status='on' ORDER BY listdate LIMIT $offset, $rowsperpage"; 

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.