corillo181 Posted June 10, 2006 Share Posted June 10, 2006 i'm trying to use thi statement but some how is not working..[code]$level=array(0,1,2,3,4,5);if($level < 1){ echo "blah";}elseif($level >= 1){echo " blah blah"}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/ Share on other sites More sharing options...
poirot Posted June 10, 2006 Share Posted June 10, 2006 What do you want with the $level array? Do you want it to loop through all it's elements and echo different things depending on the level? For that:[code]foreach ($level as $l) { if ($l < 1) { echo "blah"; } elseif ($l >= 1) { echo " blah blah"; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44019 Share on other sites More sharing options...
joquius Posted June 10, 2006 Share Posted June 10, 2006 In this case also the elseif is pointless, as it is the opposite of the first if in any case. An else would suffice. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44029 Share on other sites More sharing options...
corillo181 Posted June 10, 2006 Author Share Posted June 10, 2006 sorry i gave a bad example/// i got a enum set from 0 to 5 on my database.. that determin the level of the user..when the user agree to something it has to change from 0 to one and so on..[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php if($level == 0){?><tr> <td colspan="3"><div align="center">This page contain adult content, and should only be view be people 18 or older.<br /> are you 18 or older? <form method="post" action="<?php $_SERVER['PHP_SELF']?>" name="yf"><label> <input type="submit" name="Submit" value="yes" /> </label> </form> by clicking yes, you agree to be 18 years of age or older.<?php if(isset($_POST['Submit'])){$query=mysql_query("UPDATE tra_users SET level='1' WHERE username='$username'")or die(mysql_error);}?><?php}elseif($level >= 1){echo "blah"}?>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44033 Share on other sites More sharing options...
.josh Posted June 10, 2006 Share Posted June 10, 2006 not 100% on this but i think that enum data type is a string datatype so i think you have to put quotes around your numbers there like[code]if ($level == '0') {..} elseif ($level >= '1') {..}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44062 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 that didn't work either.. is there any other way to deal with something like this? Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44165 Share on other sites More sharing options...
AndyB Posted June 11, 2006 Share Posted June 11, 2006 Well, I assume there's far more code than we're seeing - at least I assume so. There's no database connection and no way in which $level gets any value at the start of that code. If I read the logic right, the form submit is only checked when $level = 0 (otherwise, it always drops through to the else). Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44168 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 mm i didn't posted the whole code because is a big script , i jus tposted the part i know i'm having trouble with and $level gets it's value from $_session wich is passed on with every page.. everything is set up like is supossed to.. it's just tha tpart that i don't know how to make it work.. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44174 Share on other sites More sharing options...
.josh Posted June 11, 2006 Share Posted June 11, 2006 just for shits and grins, put this before your if statement:echo "level: ".$level;and post what it echos Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44200 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 i don't know whats wrong with it, when ppl agree it does change from 0 to 1 but when i echo it out it echo 0: level 0 .. even is in the database is change to 1 for that user..any one knows why is this? Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44273 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 any one has a level system that can tell me how they got it to work ? Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44331 Share on other sites More sharing options...
redarrow Posted June 11, 2006 Share Posted June 11, 2006 [!--quoteo(post=382563:date=Jun 11 2006, 05:41 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:41 PM) [snapback]382563[/snapback][/div][div class=\'quotemain\'][!--quotec--]any one has a level system that can tell me how they got it to work ?[/quote]what for users![!--quoteo(post=382564:date=Jun 11 2006, 05:48 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 11 2006, 05:48 PM) [snapback]382564[/snapback][/div][div class=\'quotemain\'][!--quotec--]what for users![/quote]Exsplain the consept of your script or post it ok,i can not guess. according with the help above there all correct Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44332 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 i want to make something like if a user has a level 5 he can do anything tot he site like a level 5 will be a admin, a level 1 would be someone that agree to somethings.. like that.. i made a enum('0','1','2','3','4'5')and i passed the level in a $_session and tryed using if($level > 0 ){ do this}, but it doesn't work.. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44335 Share on other sites More sharing options...
AndyB Posted June 11, 2006 Share Posted June 11, 2006 If $level is saved in a session ....... then you need to retrieve the session value in any script where $level is used AND when you change $level you need to put it into the database AND update the value saved as the session variable - otherwise, you'll be looking at an outdated (and wrong) session value. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44338 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 look at the 3rd post thats is the example of what i did tell me how i can chang eit to make it work, becuase it does change but the value as you say stay the same i don't know how to change that.. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44341 Share on other sites More sharing options...
redarrow Posted June 11, 2006 Share Posted June 11, 2006 [!--quoteo(post=382567:date=Jun 11 2006, 05:54 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:54 PM) [snapback]382567[/snapback][/div][div class=\'quotemain\'][!--quotec--]i want to make something like if a user has a level 5 he can do anything tot he site like a level 5 will be a admin, a level 1 would be someone that agree to somethings.. like that.. i made a enum('0','1','2','3','4'5')and i passed the level in a $_session and tryed using if($level > 0 ){ do this}, but it doesn't work..[/quote]know any level that the user is the code will do as long as you set the do somethink.example [code]<?$query="select * from xxxxxx where id='$id'";$result=mysql_query($query);while ($record=mysql_fetch_assoc($result)){if($record["level"] >=0) {do somethink}else{echo "sorry not specified";}}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44342 Share on other sites More sharing options...
wildteen88 Posted June 11, 2006 Share Posted June 11, 2006 How is $level being populated? Are you setting the variable like so:$level = $_SESSION['level']I think you'll be best of with a switch rather than if/elseif statement like so:[code]<?phpsession_start(); //make sure you have this line whenever you are dealing with sessions$level = $_SESSION['level'];switch($level){ case 5: echo "level 5"; break; case 4: echo "level 4"; break; case 3: echo "level 3"; break; case 2: echo "level 2"; break; case 1: echo "level 1"; break; case 0: echo "level 0"; break; defualt: die("Unknown level script has been killed! level is:" . $level) break;}[/code]When you use that depending on the value of $level it should echo out the level, if $level is not set to 0,1,2,3,4 or 5 it'll kill the script and echo the value pf $level Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44343 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 i just need to know how to repass it as a session becuase for it to wokr the user has to log out and log bakc in so when they pass by the member check the session reads the new info and is passed threw the section, so the problem is in refreshin the member section Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44346 Share on other sites More sharing options...
wildteen88 Posted June 11, 2006 Share Posted June 11, 2006 To pass the level as session do this:[code]<?phpsession_start();//put code here that gets the users level$_SESSION['level'] = $level;?>[/code]Then when you want to retrieve the session make sure you have session_start on the page that checks the user level, see my post above. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44351 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 yeah i know i already got the level passed as a section, i just neeed to refresh the section.. how i do that? Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44354 Share on other sites More sharing options...
wildteen88 Posted June 11, 2006 Share Posted June 11, 2006 What do you mean by refresh? Do want the browser to refesh the page? If so why?To refresh the page in javascript you can do this:[code]header("Refresh: 0; url=" . $_SERVER['PHP_SELF']);[/code]provided that you dont have any output to the browser before you use that code. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44357 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 no.. not the page... you know , when you change something that is passed by $_session it wont take effect until th euser close the current section and open a new one.. you know that right?so what i need is a way for when the user change something that is used by a section to refresh that user section so the new information is in his current section. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44361 Share on other sites More sharing options...
wildteen88 Posted June 11, 2006 Share Posted June 11, 2006 Session data is updated automatically so you dont need to create a new session for the data come available! Where did you get that from? Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44364 Share on other sites More sharing options...
corillo181 Posted June 11, 2006 Author Share Posted June 11, 2006 because i did a form and in the form it agree to set the level from 1 0 to 1 and when the i press the agree it change from 0 to 1, but when i try echo out the level it echo out 0 and when i destroy the session and stared a new one, it did echo out a 1. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44365 Share on other sites More sharing options...
wildteen88 Posted June 11, 2006 Share Posted June 11, 2006 Was you echoing out $level or $_SESSION['level']. If you was echoing out $level that will not update as holds the old value of level session. If you echo'd out $_SESSION['level'] that should echo out your new level that you set with the form.Looks you have a bug in your script somewhere if the new session data isn't comming through. Quote Link to comment https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.