0

It seems there's something wrong with this. I don't get any distinct errors, but it's simply not doing what its supposed to be doing. I'm leaning towards there being a problem with the OR statements, but I've put the username in parenth, and the id slots in parenth, and neither work. Honestly, i'm only posting this here because five hours of looking at it got to be enough for me. Hopefully something looks blatantly wrong and it's not somewhere else in the code :/

$fetch_userone_idslots = mysql_query("SELECT id_1, id_2, id_3, id_4, id_5, id_6 FROM users WHERE id_1 = '$battle_id' || id_2 = '$battle_id || id_3 = '$battle_id || id_4 = '$battle_id || id_5 = '$battle_id || id_6 = '$battle_id && username == '$user_logged_in'");

while ($row = mysql_fetch_array($fetch_userone_idslots)){
$useroneidslot_1 = $row['id_1'];
$useroneidslot_2 = $row['id_2'];
$useroneidslot_3 = $row['id_3'];
$useroneidslot_4 = $row['id_4'];
$useroneidslot_5 = $row['id_5'];
$useroneidslot_6 = $row['id_6'];
}
2

3 Answers 3

4

You are using a == which does not exist in MySQL. Use just =. You can simplify your query like this

SELECT id_1, id_2, id_3, id_4, id_5, id_6 FROM users
WHERE '$battle_id' in (id_1, id_2, id_3, id_4, id_5, id_6) 
and username = '$user_logged_in'
Sign up to request clarification or add additional context in comments.

2 Comments

Use can use != in MySQL. But normally <> is used.
Both <> and != may be used. See Operator 'not equal'
1

in MySQL you need to use AND or OR not || and &&. and one more thing there is no ==, use only =.

SELECT id_1, id_2, id_3, id_4, id_5, id_6 
FROM users 
WHERE (
      id_1 = '$battle_id' OR 
      id_2 = '$battle_id' OR  
      id_3 = '$battle_id' OR 
      id_4 = '$battle_id' OR  
      id_5 = '$battle_id' OR  
      id_6 = '$battle_id'
      ) AND 
      username = '$user_logged_in'

1 Comment

Wrong for || and &&. See Logical operators in MySQL
0

EDIT:

Don't use == if you need an eqation. In SQL == is just =. SQL is differnet that C, it's a query language and syntax is different because it's used for different puprose. My advice is to follow the SQL sintax to avoid similar mistakes.

4 Comments

Wrong for || and &&. See Logical operators in MySQL
yes but there is no == it is just = in equations. It is better to follow the correct SQL syntax even || and && may work in MySQL. As you see followng this wrong way the guy is used == instead of =.
Your answer is wrong because it says || and && may not be used in MySQL. Update your answer to make it more clear by clicking 'edit'.
@Jocelyn, my friend, my answer is half right and half wrong - do you think == could be used in SQL expression? If you prefer the wrong part - it is ok for me - but following the SQL standart is better than the concreate implementation in MySQL. I will edit my answer, but giving the guy a feeling that SQL is C like language will reflect on understanding of SQL and it is not a good idea. Any way that's not my problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.