472,958 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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
Jul 16 '05 #1
3 22834
DB
In news:3e****************@news.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.
Jul 16 '05 #2
In message <3e****************@news.btclick.com>, James
<Ja***@nothere.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
Jul 16 '05 #3

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
James @ nothere.com (James) wrote in message
news:<3e****************@news.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: co*******@scriptsmiths.com
Web: http://www.scriptsmiths.com
----------------------------------------------------------------------------
--
Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
5
by: Leon | last post by:
Is there anyway I could clean-up all these ElseIF statements with a select/case or is this the best that can be done ("I can't think of a better way")? Private Sub Update_Click(ByVal sender As...
6
by: Ivan Sergio Borgonovo | last post by:
First thanks to Tom Lane who helped me promptly. Now let's come to the problem: create or replace function testa( ) returns char(32) as ' begin if 1=2 then if 1=2 then
3
by: xSmilinx | last post by:
Hey guys.. Im a total beginner to VB :) Im not sure if i was supposed to post this here or in the Access Forums as im using VB in Access. But heres my code: Private Sub English1_GotFocus() ...
3
by: amrhi | last post by:
Hy guys , I try to make conditional statement by using if and elseif . the problem are if i use 2 conditional statement the script run well but if try add more conditinal statement it's not working...
1
by: RobinAG | last post by:
I'm having a wierd difficulty with my If...ElseIf...Else...End If statement. I'm having the db put together a string to base a recordset off of, and depending on the ID number, the select...
17
by: JRough | last post by:
I'm trying to get error proof code. I have this code which seems to work but now I look at it I think it should be elseif not else and I wonder why it works. It is in the block:...
3
by: Tim Roberts | last post by:
JRough <jlrough@yahoo.comwrote: More than the syntax problems, you also have a logic problem here. How do you think that "if" statement is ever going to be hit, given the statement immediately...
13
by: scottbouley | last post by:
HELP! I'm trying to check a form for missing values. Two of the fields are required and therefore the corresponding message boxes are VBOkOnly. The other two are for warning purposes and their...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.