Jump to content

[SOLVED] OR syntax


Minase

Recommended Posts

hy there i am working on a new script,but it seem that this query doesnt work quite well ..

 

$buddys = "SELECT * FROM `" . DBPREFIX . "buddys` WHERE `FID` = " . $user->ID . " OR `ID` = " . $user->ID . " AND `Type` = '1'";

i want the query to check if FID = $user->ID OR ID = $user->ID one of them, and Type = 1;

thanks

Link to comment
https://forums.phpfreaks.com/topic/121759-solved-or-syntax/
Share on other sites

Without parenthesis, AND takes precedence, so your code is actually seeing if:

 

FID = $user->ID OR (ID = $user->ID AND type = 1)

 

So, you need to set off the OR with parentheticals:

<?php
$buddys = "SELECT * FROM `" . DBPREFIX . "buddys` WHERE (`FID` = " . $user->ID . " OR `ID` = " . $user->ID . ") AND `Type` = '1'";
?>

Link to comment
https://forums.phpfreaks.com/topic/121759-solved-or-syntax/#findComment-628132
Share on other sites

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.