sungpeng Posted May 24, 2009 Share Posted May 24, 2009 $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 More sharing options...
jackpf Posted May 24, 2009 Share Posted May 24, 2009 Try putting or die(mysql_error()) after the query. Link to comment https://forums.phpfreaks.com/topic/159456-solved-statuson-function-is-not-working/#findComment-841138 Share on other sites More sharing options...
sungpeng Posted May 24, 2009 Author Share Posted May 24, 2009 $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. Link to comment https://forums.phpfreaks.com/topic/159456-solved-statuson-function-is-not-working/#findComment-841188 Share on other sites More sharing options...
sungpeng Posted May 24, 2009 Author Share Posted May 24, 2009 $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? Link to comment https://forums.phpfreaks.com/topic/159456-solved-statuson-function-is-not-working/#findComment-841193 Share on other sites More sharing options...
PFMaBiSmAd Posted May 24, 2009 Share Posted May 24, 2009 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"; Link to comment https://forums.phpfreaks.com/topic/159456-solved-statuson-function-is-not-working/#findComment-841240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.