Jump to content


Photo

if()help


  • Please log in to reply
28 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 10 June 2006 - 02:50 PM

i'm trying to use thi statement but some how is not working..

$level=array(0,1,2,3,4,5);
if($level < 1){
 echo "blah";
}elseif($level >= 1){
echo " blah blah"
}



#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 10 June 2006 - 03:11 PM

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:

foreach ($level as $l) {
   if ($l < 1) {
      echo "blah";   
   } elseif ($l >= 1) {
      echo " blah blah";
   }
}

~ D Kuang

#3 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 10 June 2006 - 03:55 PM

In this case also the elseif is pointless, as it is the opposite of the first if in any case. An else would suffice.
z..z..z..z..z..z..z..z..

#4 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 10 June 2006 - 04:16 PM

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]

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 June 2006 - 06:42 PM

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

if ($level == '0') {
..
} elseif ($level >= '1') {
..
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 02:11 AM

that didn't work either.. is there any other way to deal with something like this?

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 June 2006 - 02:23 AM

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).
Legend has it that reading the manual never killed anyone.
My site

#8 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 03:49 AM

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

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 11 June 2006 - 06:15 AM

just for shits and grins, put this before your if statement:

echo "level: ".$level;

and post what it echos
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 02:07 PM

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?

#11 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 05:41 PM

any one has a level system that can tell me how they got it to work ?

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 June 2006 - 05:53 PM

[!--quoteo(post=382563:date=Jun 11 2006, 05:41 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:41 PM) View Post[/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) View Post[/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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 05:54 PM

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

#14 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 June 2006 - 06:00 PM

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.


Legend has it that reading the manual never killed anyone.
My site

#15 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 06:04 PM

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

#16 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 June 2006 - 06:04 PM

[!--quoteo(post=382567:date=Jun 11 2006, 05:54 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:54 PM) View Post[/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
<?
$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";
}
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#17 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 June 2006 - 06:07 PM

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:
<?php
session_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;
}
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

#18 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 06:11 PM

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

#19 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 June 2006 - 06:20 PM

To pass the level as session do this:
<?php
session_start();

//put code here that gets the users level

$_SESSION['level'] = $level;

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

#20 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 06:25 PM

yeah i know i already got the level passed as a section, i just neeed to refresh the section..

how i do that?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users