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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. ???

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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.