Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: If and OR statement Problem  (Read 445 times)

Dusty

  • Basic Member
  • *
  • Reputation Power: 21
  • Dusty has no influence.
  • Offline Offline
  • Posts: 39
  • TRD Computer Repair
    • Yahoo Instant Messenger - peewee986
    • View Profile
    • WWW
If and OR statement Problem
« on: July 11, 2010, 12:59:45 PM »
OK just a little info on what this codes is doing..   I have a page that I have locked. when it is locked it shows some thing else other then what is on the page.  that is done with a If locked show this else so that.

That works..    when it is locked I had a input spot for a code to be put in.
 ( the code is set up like this -

 if ($r['code']==0)
{
$code=rand(1,999);
mysql_query("UPDATE refer_code SET code=$code");
}      When the page is loaded if the code field on my table is 0 then it till run the rand and put a code there)

I can see this code as admin and Ill know what they code is. .. 

I then have this code here.  if ($_POST['amount']==$r['code'])   that checks if the code that was entered into the input box was right  if it is right it unlocks the page. it its not right then it does nothing.   

That works ..    But  I can only do 1 code at a time / give out 1 code at a time.   So I added 4 more ifs statement to give me 4 more codes.    that works.. 

My problem is  the other 4 codes dont unlock the page.  Because of this if statement here

   if ($_POST['amount']==$r['code'])

I need that to be like 
 If ($_POST['amount']==$r['code] OR  $r['code2] OR $r['code3] OR $r['code4] OR $r['code5])
{
Print BLA BLA BLA BLA  The page has been unlocked and
Print Bla bla bla abl whats one the page
}
Else
{
Do nothing of the sort
}

Ive set it up just as i have it type here and Ive had the OR's all || and it dont work ..  if if put in OR or || it shows the stuff that is locked before a number is put in.....     

When this is working right .. If i give some one 1 of them 5 numbers and they put that number in that number unlocks the page and then resets to a different number but does not change the other 4..  With it set with only 1 number it works just right .. I just cant get it to work with the other numbers
Logged
TRD Computer Repair Services
www.trdcomputer.com

Analog

  • Basic Member
  • *
  • Reputation Power: 8
  • Analog has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Re: If and OR statement Problem
« Reply #1 on: July 11, 2010, 08:36:10 PM »
Not knowing how you have the code stored only suggestion I can make is....

Update the field in the table to varchar

then generate your codes and store as code1:code2:code3:code4 etc...

then you can call the code from the db and use the explode function of php to make it an array and then use in_array to check the inputed code to that of the stored code...

this below is an example if you have the codes stored in single field (code1:code2:code3:code4:code5)
Code: [Select]
$code = explode(':', $r['code']);
if(in_array($_POST['code'],$code)) {
  // do whatever it is when page is unlocked
} else {
  // page is locked }
Logged

Dusty

  • Basic Member
  • *
  • Reputation Power: 21
  • Dusty has no influence.
  • Offline Offline
  • Posts: 39
  • TRD Computer Repair
    • Yahoo Instant Messenger - peewee986
    • View Profile
    • WWW
Re: If and OR statement Problem
« Reply #2 on: July 11, 2010, 11:31:24 PM »
Thanks much for your advice..   I ended up getting it to work about an hour ago. 

What i did was   
Code: [Select]
if closed or open = 1
{ // Start the on off if code
print this

/*** this code here is for when the REG is Closed it shows a unlock box to enter a code.. 
if post = code
{
print this
}
if post = code2
{
Print this
}****///// This is where that codes stops..       so I had to make my code a bit longer then I wanted it but it seems to work .. for now..  LOL     
}/// Stops  the on off if code


else


{
if is Reg is open it prints right to this .. and skips all the above..
 
print this
}


Its a very Very off the wall set of codes.. but it works for what i wanted it to do .. LOL   


And again   Thanks for your advice..  wish I would have seen it a bit sooner.   
Logged
TRD Computer Repair Services
www.trdcomputer.com

Danny696

  • Senior Member
  • ****
  • Reputation Power: 317
  • Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.
  • Offline Offline
  • Posts: 540
    • View Profile
    • WWW
Re: If and OR statement Problem
« Reply #3 on: July 12, 2010, 08:40:23 AM »
Analog, thats the worst way of doing it probabbly try this:

if($r['code'] == ($r['code1'] || $r['code2'] || $r['code3']) ) {
//what!
}
else {
//yo!
}
Logged
Project Choosen - 10%
Daniel - Hanson . Com

Analog

  • Basic Member
  • *
  • Reputation Power: 8
  • Analog has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Re: If and OR statement Problem
« Reply #4 on: July 12, 2010, 11:18:37 AM »
Your entitled to your opinion, but I don't agree...

Logged

Danny696

  • Senior Member
  • ****
  • Reputation Power: 317
  • Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.
  • Offline Offline
  • Posts: 540
    • View Profile
    • WWW
Re: If and OR statement Problem
« Reply #5 on: July 12, 2010, 11:47:08 AM »
LMAO, ever since the implode/explode craze, everyones using it.

How many people keep things as 1:2:3:4:5 really -.-
Logged
Project Choosen - 10%
Daniel - Hanson . Com
 


This forum is now closed and has moved to a new location! Click here to find out why.