Professional Web Applications Themes

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

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.querystring("A") queryB = request.querystring("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...

  1. #1

    Default 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.querystring("A")
    queryB = request.querystring("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
    James Guest

  2. #2

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

    In news:3ef953a4.167992089news.btclick.com,
    James nothere.com (James) <James nothere.com (James)> typed:
    > 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.querystring("A")
    > queryB = request.querystring("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
    If ($a) {
    SQL STATEMENT
    } elseif ($b) {
    ANOTHER SQL STATEMENT
    }

    D.


    DB Guest

  3. #3

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

    In message <3ef953a4.167992089news.btclick.com>, James
    <Jamesnothere.com> writes
    >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.querystring("A")
    >queryB = request.querystring("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

    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
    Rob Allen Guest

  4. #4

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


    "Nikolai Chuvakhin" <nciname.com> wrote in message
    news:32d7a63c.0306250838.3f7583a9posting.google.c om...
    > James nothere.com (James) wrote in message
    > news:<3ef953a4.167992089news.btclick.com>...
    > >
    > >
    > > How do I do this in PHP ??
    >
    > 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.

    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
    }

    >
    > Cheers,
    > NC
    Thanks,
    Mark
    ----------------------------------------------------------------------------
    --
    Windows, Linux and Internet Development Consultant
    Email: [email]corporatescriptsmiths.com[/email]
    Web: [url]http://www.scriptsmiths.com[/url]
    ----------------------------------------------------------------------------
    --


    The Script Smiths - PHP/PERL Developers Guest

Similar Threads

  1. pl/pgsql trigger: syntax error at or near "ELSEIF"
    By Roman Neuhauser in forum PostgreSQL / PGSQL
    Replies: 3
    Last Post: January 14th, 04:24 PM
  2. Replies: 0
    Last Post: September 11th, 11:26 AM
  3. Replies: 0
    Last Post: September 11th, 12:19 AM
  4. failing elseif construct
    By Bert in forum PHP Development
    Replies: 5
    Last Post: August 12th, 08:44 PM
  5. Replies: 0
    Last Post: April 15th, 01:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139