If - ElseIf - SQL Select... ASP YES.. PHP NO ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James

    If - ElseIf - SQL Select... ASP YES.. PHP NO ???

    Hi,
    I have a form with 2 fields.
    'A'
    'B'

    The user completes one of the fields and the form is submitted.

    On the results page I want to run a query, but this will change
    subject to which field is completed.

    In ASP I can use:

    queryA = request.queryst ring("A")
    queryB = request.queryst ring("B")

    If QueryA <>"" then
    SQL STATEMENT

    Elseif QueryB <> then
    ANOTHER SQL STATEMENT

    End If


    The pages checks for a value in QueryA or QueryB then creates the
    correct SQL Statement..

    How do I do this in PHP ??

    Thanks
  • DB

    #2
    Re: If - ElseIf - SQL Select... ASP YES.. PHP NO ???

    In news:3ef953a4.1 67992089@news.b tclick.com,
    James @ nothere.com (James) <James @ nothere.com (James)> typed:[color=blue]
    > Hi,
    > I have a form with 2 fields.
    > 'A'
    > 'B'
    >
    > The user completes one of the fields and the form is submitted.
    >
    > On the results page I want to run a query, but this will change
    > subject to which field is completed.
    >
    > In ASP I can use:
    >
    > queryA = request.queryst ring("A")
    > queryB = request.queryst ring("B")
    >
    > If QueryA <>"" then
    > SQL STATEMENT
    >
    > Elseif QueryB <> then
    > ANOTHER SQL STATEMENT
    >
    > End If
    >
    >
    > The pages checks for a value in QueryA or QueryB then creates the
    > correct SQL Statement..
    >
    > How do I do this in PHP ??
    >
    > Thanks[/color]

    If ($a) {
    SQL STATEMENT
    } elseif ($b) {
    ANOTHER SQL STATEMENT
    }

    D.


    Comment

    • Rob Allen

      #3
      Re: If - ElseIf - SQL Select... ASP YES.. PHP NO ???

      In message <3ef953a4.16799 2089@news.btcli ck.com>, James
      <James@nothere. com> writes[color=blue]
      >Hi,
      >I have a form with 2 fields.
      >'A'
      >'B'
      >
      >The user completes one of the fields and the form is submitted.
      >
      >On the results page I want to run a query, but this will change
      >subject to which field is completed.
      >
      >In ASP I can use:
      >
      >queryA = request.queryst ring("A")
      >queryB = request.queryst ring("B")
      >
      >If QueryA <>"" then
      >SQL STATEMENT
      >
      >Elseif QueryB <> then
      >ANOTHER SQL STATEMENT
      >
      >End If
      >
      >
      >The pages checks for a value in QueryA or QueryB then creates the
      >correct SQL Statement..
      >
      >How do I do this in PHP ??
      >
      >Thanks[/color]


      If(isset($_GET['A']) && $_GET['A'] != "")
      {
      // do something as a result of A being set
      }
      else if(isset($_GET['B']) && $_GET['B'] != "" )
      {
      // do somethign as a result of B being set
      }
      else
      {
      // neither set to something other than ""
      }

      --
      Rob Allen

      Comment

      • The Script Smiths  - PHP/PERL Developers

        #4
        Re: If - ElseIf - SQL Select... ASP YES.. PHP NO ???


        "Nikolai Chuvakhin" <nc@iname.com > wrote in message
        news:32d7a63c.0 306250838.3f758 3a9@posting.goo gle.com...[color=blue]
        > James @ nothere.com (James) wrote in message
        > news:<3ef953a4. 167992089@news. btclick.com>...[color=green]
        > >[/color][/color]
        [color=blue][color=green]
        > >
        > > How do I do this in PHP ??[/color]
        >
        > if ($_REQUEST['A']) {
        > SQL STATEMENT
        > } else {
        > if ($_REQUEST['B']) {
        > ANOTHER SQL STATEMENT
        > }
        > }
        >
        > Since you are not specifying the method your form uses, I suggested
        > the use of $_REQUEST array. If you know whether you want to use
        > GET or POST, you can use $_GET or $_POST array as well.[/color]


        Agreed, I fully recommend using $_REQUEST, etc over global variables.
        One catch though, this requires PHP 4.1.0 or higher, there are hosting
        services out there that still run 4.0.x, I know this cos I have clients with
        this problem. Then this won't work

        Prior to 4.1.0 there was no equivalent of $_REQUEST, so I guess you could
        use globals if you must, otherwise use one of $HTTP_POST_VARS for forms,
        $HTTP_GET_VARS for normal url gets.

        Note, you can also write the above more compactly as:

        if ( $_REQUEST['A'] ) {
        SQL STATEMENT
        }elseif ( $_REQUEST['B'] ) {
        ANOTHER SQL
        }

        [color=blue]
        >
        > Cheers,
        > NC[/color]

        Thanks,
        Mark
        ----------------------------------------------------------------------------
        --
        Windows, Linux and Internet Development Consultant
        Email: corporate@scrip tsmiths.com
        Web: http://www.scriptsmiths.com
        ----------------------------------------------------------------------------
        --


        Comment

        Working...