Aureole Posted November 10, 2007 Share Posted November 10, 2007 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 https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/ Share on other sites More sharing options...
teng84 Posted November 10, 2007 Share Posted November 10, 2007 $query ="SELECT * FROM `categories` WHERE cat_access_level >= '{$_SESSION['mem_access_level']}' AND cat_visible = '1' ORDER BY cat_id"; try Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388290 Share on other sites More sharing options...
Barand Posted November 10, 2007 Share Posted November 10, 2007 do they all have cat_visible = 1? Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388291 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 Yes all three of them. I'm sorry to say your suggestion didn't make a difference either teng. ??? MYSQL eludes me sometimes. Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388293 Share on other sites More sharing options...
Barand Posted November 10, 2007 Share Posted November 10, 2007 try $query ="SELECT * FROM `categories` WHERE cat_access_level>='1' AND cat_visible='1' ORDER BY cat_id"; If that works then maybe you need to call session_start() first. Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388294 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 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? ??? Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388297 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 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 https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388301 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 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 https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388323 Share on other sites More sharing options...
Barand Posted November 10, 2007 Share Posted November 10, 2007 What happened to the while() loop you had in your first post? Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388324 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 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 https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388328 Share on other sites More sharing options...
eXeCuTeR Posted November 10, 2007 Share Posted November 10, 2007 Darn, I was just about to ask if you have multiple variables ^^ Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388330 Share on other sites More sharing options...
Aureole Posted November 10, 2007 Author Share Posted November 10, 2007 Ah well, maybe next time? Link to comment https://forums.phpfreaks.com/topic/76699-solved-in-sql-statement-isnt-working-as-expected/#findComment-388362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.