473,416 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 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 22939
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.