Jump to content

[SOLVED] >= in SQL Statement isn't working as expected


Aureole

Recommended Posts

This should show 3 categories, it only shows 1.

 

<?php
// I will explicitly set the variable here to 1 for testing purposes in case it wasn't set correctly on the sign in page.
$_SESSION['mem_access_level'] = 1;
$query ="SELECT * FROM `categories` WHERE cat_access_level>='{$_SESSION['mem_access_level']}' AND cat_visible='1' ORDER BY cat_id";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) 
{
    // Do stuff.
}
?>

 

I have 3 Categories with access levels of 1, 2 and 3. Only the 1st one is showing up. Any ideas?

I didn't post the entire file, session_start(); is the first thing to go at the top of all of my files. I will try it nonetheless.

 

EDIT: Alas, that attempt was fruitless.

 

Anyone else got an idea they'd like to throw in the pot? ???

Even this won't work, I'm beginning to feel an urge to slam my head against the desk several times, hmm.

 

$query = "SELECT * FROM `categories` WHERE `cat_access_level` = '1' OR `cat_access_level` > '1' AND cat_visible = '1' ORDER BY `cat_id`";

 

The above actually shows no categories whatsoever.

Get this. Upon 'uberly-debugging' I find that the query is returning 3 rows, so why isn't is showing them?

 

$_SESSION['mem_access_level'] = 1;
$query = "SELECT * FROM `categories` WHERE `cat_access_level` >= '1' AND cat_visible = '1' ORDER BY `cat_id`";
$result = mysql_query($query) or die(mysql_error());

$uberdebug = mysql_num_rows($result);
echo $uberdebug;
exit;

 

^ Returns 3. ???

The while loop was after the exit;

 

No worries I have solved my problem, it was so blatantly obvious staring me in the face. I name all my queries '$query', all my results '$result' etc. Apparently that caused interference, it's all fixed now.

 

Thank you all for your help anyway. :)

 

*Gives you a patience sticker*

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.