9 Replies - 1285 Views - Last Post: 20 January 2003 - 03:34 AM Rate Topic: -----

#1 Ruck  Icon User is offline

  • $

Reputation: -5
  • View blog
  • Posts: 1,033
  • Joined: 03-September 01

Variables (yet another)

Posted 10 January 2003 - 10:24 AM

I have a script and I'm using variable definition in the URL to bring up certain pages (ie. ?show=cp, etc.). The problem I'm having is when I try to use more than one variable using the code below in the if statement and the URL ?show=cp&action=post.

if (($show == cp) & ($action == post)) {

I've seen in places before that you need to do something in particular to get this kind of thing to work. What exactly is that?

Is This A Good Question/Topic? 0
  • +

Replies To: Variables (yet another)

#2 MathewS  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 342
  • Joined: 14-May 02

Re: Variables (yet another)

Posted 10 January 2003 - 11:23 AM

you should use two && or two || ie

if (($show == cp) && ($action == post)) {



i think thats right anyway :S
Was This Post Helpful? 0
  • +
  • -

#3 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Variables (yet another)

Posted 10 January 2003 - 11:59 AM

matt your right you need the && or the || otherwise you are going to get errors...
Was This Post Helpful? 0
  • +
  • -

#4 Ruck  Icon User is offline

  • $

Reputation: -5
  • View blog
  • Posts: 1,033
  • Joined: 03-September 01

Re: Variables (yet another)

Posted 10 January 2003 - 04:10 PM

Odd, I tried that. Let me give it another shot..
Was This Post Helpful? 0
  • +
  • -

#5 gneato  Icon User is offline

  • <title>Untitled Document</title>

Reputation: 0
  • View blog
  • Posts: 1,311
  • Joined: 03-September 01

Re: Variables (yet another)

Posted 10 January 2003 - 04:17 PM

The corrext syntax includes quotes around the 'cp' in the if statement, as well as double &'s.

if (($show == 'cp') && ($action == 'post')) {
blah();
}


This applies whenever you're dealing with a string. This is not necessary with integers, as
if ($num == 3)
blah();
}
is acceptable.
Was This Post Helpful? 0
  • +
  • -

#6 arniie  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 999
  • Joined: 08-October 02

Re: Variables (yet another)

Posted 11 January 2003 - 07:19 AM

Quote

if ($num == 3)
blah();
}


surely that wouldn't work as you haven't opened the if statement ( missing { )

??
Was This Post Helpful? 0
  • +
  • -

#7 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Variables (yet another)

Posted 11 January 2003 - 12:10 PM

no, arnie, that wouldn't work, but it's also just a simple error...yes you would need opening and closing {} unless there's only one statement within the if statement
Was This Post Helpful? 0
  • +
  • -

#8 gneato  Icon User is offline

  • <title>Untitled Document</title>

Reputation: 0
  • View blog
  • Posts: 1,311
  • Joined: 03-September 01

Re: Variables (yet another)

Posted 13 January 2003 - 09:12 AM

arniie, on Jan 11 2003, 08:19 AM, said:

Quote

if ($num == 3)
blah();
}


surely that wouldn't work as you haven't opened the if statement ( missing { )

??

'twas a simple typo; surely you understand.
Was This Post Helpful? 0
  • +
  • -

#9 arniie  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 999
  • Joined: 08-October 02

Re: Variables (yet another)

Posted 13 January 2003 - 09:37 AM

yeah - sorry- i wasn't having a go...I was actually wondering if that worked...for a minute
Was This Post Helpful? 0
  • +
  • -

#10 echo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-January 03

Re: Variables (yet another)

Posted 20 January 2003 - 03:34 AM

Since globals are turned of now by default, you have to use $_GET["show"] or $_POST["show"] (use $_GET[""] when you get variables from an URL)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1