Jump to content

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"; 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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