473,388 Members | 1,207 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,388 software developers and data experts.

else or elseif?

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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?
or should it be

if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: ".$_POST[redirect'}".php?);

this would get a default else. I am not sure but I think this would
redirect the page back to the starting point?

thanks,

if(empty($id)){
$vars = "type=".$type."&param=".$param;
$th = "<th><a href='idle_cars.php?".$vars."&order_by=lease'>Rout e</
a></th>";
$TPL_carnumbers = GetHeaders($th,$vars);
$result = GetCars(0,$type,$param,CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,$param);
}else{
$vars = "id=".$id."&type=".$type."&param=".$param;
$TPL_carnumbers = GetHeaders('',$vars);
if($_SESSION["LMS_USER_DESC"]=='customer'){
$result = GetCustomerCars($id,'',$param,CLM_order_by($order_ by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param);
}else{
$result = GetCars($id,'leased',$param,CLM_order_by($order_by ));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param)." ".GetLeaseCompName($id);
}
}

if ($_POST['assign']!='Open in Excel'){

if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);

} else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($id,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";
}elseif ($_POST['assign']=='Open in Excel'){
while ($row = mysql_fetch_assoc($result)){

Header("Location: idle_carsXL.php");
exit;
}

}
Jul 28 '08 #1
17 2429
JRough schreef:
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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?
Hi,

Probably yes, that code above doesn't make sense. It has more problems.

Look:
if($_POST('assign']='Open in Excel')

is strange: It doesn't test for $_POST('assign'] being the same as 'Open
in Excel', but ASSIGN 'Open in Excel' to $_POST('assign'].
I think it was ment to say == instead of =.

Since the current code if($_POST('assign']='Open in Excel') ALWAYS
evaluate to true (because this assignment always do that), it needs fixing.

Even if you fix this, PHP will NEVER arive at the code inside the elseif.

http://nl2.php.net/manual/en/control...res.elseif.php

I didn't look through the rest of the code, but maybe this helps you
untangle the issue: elseif is NEVER needed. It is just a shorthand.
The following codefragments are equivalent:

if (..expresion1..){
// code if expresion1 is true.
elseif (..expresion2..){
// code if expresion1 is false and expresion2 is true.
} else {
// code if expresion 1 is false, and expresion2 is false.
}

The above executes the same as:

if (..expresion1..){
// code if expresion1 is true.
} else {
if (..expresion2..){
// code if expresion1 is false and expresion2 is true.
} else {
// code if expresion 1 is false, and expresion2 is false.
}
}

Personally I prefer the second over the first because it is clearer how
the blocks {} work.

Hope that helps.
And be sure you check for more = instead of == in that code when you see
an if. It seems like a VB 'programmer' made that code. ;-)

Regards,
Erwin Moller

or should it be

if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: ".$_POST[redirect'}".php?);

this would get a default else. I am not sure but I think this would
redirect the page back to the starting point?

thanks,

if(empty($id)){
$vars = "type=".$type."&param=".$param;
$th = "<th><a href='idle_cars.php?".$vars."&order_by=lease'>Rout e</
a></th>";
$TPL_carnumbers = GetHeaders($th,$vars);
$result = GetCars(0,$type,$param,CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,$param);
}else{
$vars = "id=".$id."&type=".$type."&param=".$param;
$TPL_carnumbers = GetHeaders('',$vars);
if($_SESSION["LMS_USER_DESC"]=='customer'){
$result = GetCustomerCars($id,'',$param,CLM_order_by($order_ by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param);
}else{
$result = GetCars($id,'leased',$param,CLM_order_by($order_by ));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param)." ".GetLeaseCompName($id);
}
}

if ($_POST['assign']!='Open in Excel'){

if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);

} else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($id,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";
}elseif ($_POST['assign']=='Open in Excel'){
while ($row = mysql_fetch_assoc($result)){

Header("Location: idle_carsXL.php");
exit;
}

}
Jul 28 '08 #2
..oO(JRough)
>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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?
"elseif" is used to check another condition than just the one used in
the "if" part. But the above is syntactically wrong in many aspects and
doesn't really make sense. In the snippet you attached it's like this:

if ($_POST['assign'] != 'Open in Excel') {
...
} elseif ($_POST['assign'] == 'Open in Excel') {
...
}

And there the "elseif" indeed is not really necessary. But doesn't hurt
either. I'm just wondering what this part is supposed to mean:

while ($row = mysql_fetch_assoc($result)) {
Header("Location: idle_carsXL.php");
exit;
}

The Location header is invalid and the entire block totally useless. Why
the loop?
>or should it be

if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: ".$_POST[redirect'}".php?);

this would get a default else. I am not sure but I think this would
redirect the page back to the starting point?
The above doesn't redirect anywhere, since it's just a syntactical mess.
It's not even clear to me what the code is supposed to do.

Micha
Jul 28 '08 #3
In article
<99**********************************@v1g2000pra.g ooglegroups.com>,
JRough <jl*****@yahoo.comwrote:
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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?
or should it be

if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: ".$_POST[redirect'}".php?);

this would get a default else. I am not sure but I think this would
redirect the page back to the starting point?

thanks,

if(empty($id)){
$vars = "type=".$type."&param=".$param;
$th = "<th><a href='idle_cars.php?".$vars."&order_by=lease'>Rout e</
a></th>";
$TPL_carnumbers = GetHeaders($th,$vars);
$result = GetCars(0,$type,$param,CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,$param);
}else{
$vars = "id=".$id."&type=".$type."&param=".$param;
$TPL_carnumbers = GetHeaders('',$vars);
if($_SESSION["LMS_USER_DESC"]=='customer'){
$result = GetCustomerCars($id,'',$param,CLM_order_by($order_ by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param);
}else{
$result = GetCars($id,'leased',$param,CLM_order_by($order_by ));
$MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param)." ".GetLeaseCompName($id);
}
}

if ($_POST['assign']!='Open in Excel'){

if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);

} else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($id,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";
}elseif ($_POST['assign']=='Open in Excel'){
while ($row = mysql_fetch_assoc($result)){

Header("Location: idle_carsXL.php");
exit;
}

}

Having laid this out in what is for me a more legible form I get the
following, and it seems quite clear that the elseif is unnecessary. But
it doesn't harm.

if (empty($id))
{
$vars = "type=" . $type . "&param=" . $param;
$th = "<th><a href='idle_cars.php?" . $vars .
"&order_by=lease'>Route</a></th>";
$TPL_carnumbers = GetHeaders ($th, $vars);
$result = GetCars (0, $type, $param, CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT " . GetHeading
($type,$param);
}
else {
$vars = "id=" . $id . "&type=" . $type . "&param=" . $param;
$TPL_carnumbers = GetHeaders('',$vars);
if ($_SESSION["LMS_USER_DESC"]=='customer')
{
$result = GetCustomerCars ($id, '', $param,
CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT " . GetHeading
($type,$param);
}
else {
$result = GetCars ($id, 'leased', $param,
CLM_order_by($order_by));
$MSG_carlist = "IDLE CARS - NO MOVEMENT " . GetHeading ($type,
$param) . " " . GetLeaseCompName($id);
}
}

if ($_POST['assign']!='Open in Excel')
{
if (mysql_numrows($result)==0)
{
$TPL_carnumbers .= GetNoCarsMsg ($th);
}
else {
while ($row = mysql_fetch_assoc($result))
{
$TPL_carnumbers .= MakeSighting ($id, $row);
}
}

$TPL_carnumbers .= "</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";

}
elseif ($_POST['assign']=='Open in Excel')
{
while ($row = mysql_fetch_assoc($result))
{
Header ("Location: idle_carsXL.php");
exit;
}

}
Jul 28 '08 #4
On Jul 28, 9:34*am, Michael Fesser <neti...@gmx.dewrote:
.oO(JRough)
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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?

"elseif" is used to check another condition than just the one used in
the "if" part. But the above is syntactically wrong in many aspects and
doesn't really make sense. In the snippet you attached it's like this:

if ($_POST['assign'] != 'Open in Excel') {
* ...

} elseif ($_POST['assign'] == 'Open in Excel') {
* ...
}

And there the "elseif" indeed is not really necessary. But doesn't hurt
either. I'm just wondering what this part is supposed to mean:

* while ($row = mysql_fetch_assoc($result)) {
* * Header("Location: idle_carsXL.php");
* * exit;
* }

The Location header is invalid and the entire block totally useless. Why
the loop?
or should it be
if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: *".$_POST[redirect'}".php?);
this would get a default else. *I am not sure but I think this would
redirect the page back to the starting point?

The above doesn't redirect anywhere, since it's just a syntactical mess.
It's not even clear to me what the code is supposed to do.

Micha
Actually the location header does work as it redirects to the page
otherewise it would stay on the same page. The redirect doesn't go
anywhere it was just supposed to be a default value for error checking
for the if statement. If it is not excel do this if it is excel do
this but if it is an error reload the page. I was just trying to
come up with a default value for error checking.

the $result variable parses a query from a function that is called
getcustomercars()
thanks,
Jul 28 '08 #5
..oO(JRough)
>On Jul 28, 9:34*am, Michael Fesser <neti...@gmx.dewrote:
>>
>if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: *".$_POST[redirect'}".php?);
>this would get a default else. *I am not sure but I think this would
redirect the page back to the starting point?

The above doesn't redirect anywhere, since it's just a syntactical mess.
It's not even clear to me what the code is supposed to do.

Actually the location header does work as it redirects to the page
otherewise it would stay on the same page.
The HTTP specification requires an absolute URI in the Location header.
In this snippet

while ($row = mysql_fetch_assoc($result)) {
Header("Location: idle_carsXL.php");
exit;
}

you use a relative URI, which is a bug, because it violates the spec and
will even cause a warning in some browsers. And I'm still wondering what
the while loop is doing there.
>The redirect doesn't go
anywhere it was just supposed to be a default value for error checking
for the if statement. If it is not excel do this if it is excel do
this but if it is an error reload the page. I was just trying to
come up with a default value for error checking.

the $result variable parses a query from a function that is called
getcustomercars()
OK, but is there still something unclear or another question? The code
snippets above don't make much sense, so if there's still some kind of a
problem, please post some real code.

Micha
Jul 28 '08 #6
On Jul 28, 9:34*am, Michael Fesser <neti...@gmx.dewrote:
.oO(JRough)
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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?

"elseif" is used to check another condition than just the one used in
the "if" part. But the above is syntactically wrong in many aspects and
doesn't really make sense. In the snippet you attached it's like this:

if ($_POST['assign'] != 'Open in Excel') {
* ...

} elseif ($_POST['assign'] == 'Open in Excel') {
* ...
}

And there the "elseif" indeed is not really necessary. But doesn't hurt
either. I'm just wondering what this part is supposed to mean:

* while ($row = mysql_fetch_assoc($result)) {
* * Header("Location: idle_carsXL.php");
* * exit;
* }

The Location header is invalid and the entire block totally useless. Why
the loop?
or should it be
if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: *".$_POST[redirect'}".php?);
this would get a default else. *I am not sure but I think this would
redirect the page back to the starting point?

The above doesn't redirect anywhere, since it's just a syntactical mess.
It's not even clear to me what the code is supposed to do.

Micha
Are you saying the test should be

if (empty($_POST){
draw report in broswer}
elseif (<empty($_POST){
pull report in Excel}

instead of not testing for the Excel button named 'assign'?

What if there was more in the form than one button? How would you
test for that?
I don't get why that was wrong?

if ($_POST)'assign']!= 'Open in Excel')
why does this always evaluate to true?

thanks
Jul 28 '08 #7
JRough schreef:
On Jul 28, 9:34 am, Michael Fesser <neti...@gmx.dewrote:
>.oO(JRough)
>>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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?
"elseif" is used to check another condition than just the one used in
the "if" part. But the above is syntactically wrong in many aspects and
doesn't really make sense. In the snippet you attached it's like this:

if ($_POST['assign'] != 'Open in Excel') {
...

} elseif ($_POST['assign'] == 'Open in Excel') {
...
}

And there the "elseif" indeed is not really necessary. But doesn't hurt
either. I'm just wondering what this part is supposed to mean:

while ($row = mysql_fetch_assoc($result)) {
Header("Location: idle_carsXL.php");
exit;
}

The Location header is invalid and the entire block totally useless. Why
the loop?
>>or should it be
if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: ".$_POST[redirect'}".php?);
this would get a default else. I am not sure but I think this would
redirect the page back to the starting point?
The above doesn't redirect anywhere, since it's just a syntactical mess.
It's not even clear to me what the code is supposed to do.

Micha

Are you saying the test should be

if (empty($_POST){
draw report in broswer}
elseif (<empty($_POST){
pull report in Excel}

instead of not testing for the Excel button named 'assign'?

What if there was more in the form than one button? How would you
test for that?
I don't get why that was wrong?

if ($_POST)'assign']!= 'Open in Excel')
why does this always evaluate to true?

thanks
if (a==1){
do_a
}
elseif (a!=1){
do_b
}
is the same as

if (a==1){
do_a
}
else{
do_b
}
but, u should use the 'elseif' in these sort of cases:

if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}
--
Luuk
Jul 28 '08 #8
On Jul 28, 9:22*am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
JRough schreef:
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:
if($_POST('assign']='Open in Excel')]...{
}elseif($_POST['assign']=='Open in Excel')]...
?
shouldn't it be else instead of elseif?

Hi,

Probably yes, that code above doesn't make sense. It has more problems.

Look:
if($_POST('assign']='Open in Excel')

is strange: It doesn't test for $_POST('assign'] being the same as 'Open
in Excel', but ASSIGN 'Open in Excel' to $_POST('assign'].
I think it was ment to say == instead of =.

Since the current code if($_POST('assign']='Open in Excel') ALWAYS
evaluate to true (because this assignment always do that), it needs fixing.

Even if you fix this, PHP will NEVER arive at the code inside the elseif.

http://nl2.php.net/manual/en/control...res.elseif.php

I didn't look through the rest of the code, but maybe this helps you
untangle the issue: elseif is NEVER needed. It is just a shorthand.
The following codefragments are equivalent:

if (..expresion1..){
* *// code if expresion1 is true.
elseif (..expresion2..){
* *// code if expresion1 is false and expresion2 is true.} else {

* *// code if expresion 1 is false, and expresion2 is false.

}

The above executes the same as:

if (..expresion1..){
* *// code if expresion1 is true.} else {

* *if (..expresion2..){
* * *// code if expresion1 is false and expresion2 is true.
* *} else {
* * *// code if expresion 1 is false, and expresion2 is false.
* *}

}

Personally I prefer the second over the first because it is clearer how
the blocks {} work.

Hope that helps.
And be sure you check for more = instead of == in that code when you see
an if. It seems like a VB 'programmer' made that code. ;-)

Regards,
Erwin Moller
or should it be
if....
elseif.....
else
($_POST['redirect']&&$_POST['redirect'}!=$_SERVER['PHP_SELF'}){
Header)"LOCATION: *".$_POST[redirect'}".php?);
this would get a default else. *I am not sure but I think this would
redirect the page back to the starting point?
thanks,
if(empty($id)){
* $vars = "type=".$type."&param=".$param;
* $th * = "<th><a href='idle_cars.php?".$vars."&order_by=lease'>Rout e</
a></th>";
* $TPL_carnumbers = GetHeaders($th,$vars);
* $result = GetCars(0,$type,$param,CLM_order_by($order_by));
* $MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,$param);
}else{
* $vars = "id=".$id."&type=".$type."&param=".$param;
* $TPL_carnumbers = GetHeaders('',$vars);
* if($_SESSION["LMS_USER_DESC"]=='customer'){
* * $result = GetCustomerCars($id,'',$param,CLM_order_by($order_ by));
* * $MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param);
* }else{
* * $result = GetCars($id,'leased',$param,CLM_order_by($order_by ));
* * $MSG_carlist = "IDLE CARS - NO MOVEMENT ".GetHeading($type,
$param)." ".GetLeaseCompName($id);
* }
}
if ($_POST['assign']!='Open in Excel'){
* *if(mysql_numrows($result)==0){
* *$TPL_carnumbers.= GetNoCarsMsg($th);
* *} * * * else{
* *while ($row = mysql_fetch_assoc($result)){
* * * * * *$TPL_carnumbers.=MakeSighting($id,$row);
* * * }
* * *}
* *$TPL_carnumbers.="</table>";
* * include "header.php";
* * include $template_path."template_carlist.html";
* * include "footer.php";
}elseif ($_POST['assign']=='Open in Excel'){
* * while ($row = mysql_fetch_assoc($result)){
* *Header("Location: idle_carsXL.php");
* * *exit;
* *}
}

The button to be tested for is this :
<td align=center>
<form action ="<?=$_SERVER['PHP_SELF']?>" method=post>
<INPUT TYPE = "image" SRC='<?=$SITEURL."images/xl2.jpg"?>'
VALUE ="Open in Excel" ALT="Open in Excel" NAME="assign"></
form>

How do you test for the button click? Maybe "assign" is fine?
if ($_POST('assign')== 'Open in Excel'
I tried
if ($_POST['assign']!='Open in Excel'){
and it doesn't work because it is an image not a button.

thanks,

Jul 28 '08 #9
..oO(JRough)
>Are you saying the test should be

if (empty($_POST){
draw report in broswer}
elseif (<empty($_POST){
pull report in Excel}
See Luuk's reply - it sums it up quite good.
>instead of not testing for the Excel button named 'assign'?
If there's just one button, you don't have to explicitly test for it.
Just check that there's a form submission:

if (empty($_POST)) {
... // browser report
} else {
... // Excel report
}

Pretty easy.
>What if there was more in the form than one button? How would you
test for that?
If you want to differentiate between various submit buttons and invoke
different actions dependent on which button was pressed, then of course
you have to perform multiple tests. An if-[elseif-]else construction
would be one way for doing this, a switch statement might be another
option. It always depends on the situation.
>I don't get why that was wrong?
There was nothing wrong about the idea, it was just about the code
snippets you posted. Some of them were not only syntactically wrong
(such code would throw parse error over parse error!), but some even
became completey confusing. You should do a straight copy 'n paste
instead of retyping larger parts of code.
>if ($_POST)'assign']!= 'Open in Excel')
why does this always evaluate to true?
Same problem - what is the _real_ code? The parser would never accept
this line! I guess you meant

if ($_POST['assign'] != 'Open in Excel') {
...
}

This would only evaluate to TRUE if $_POST['assign'] was set to
something other than 'Open in Excel'. But if the actual code is like in
your first posting:

if ($_POST['assign'] = 'Open in Excel') {
...
}

then of course it will always be TRUE, because this is an assignment,
not a comparison.

Micha
Jul 28 '08 #10
..oO(JRough)
>The button to be tested for is this :
<td align=center>
<form action ="<?=$_SERVER['PHP_SELF']?>" method=post>
<INPUT TYPE = "image" SRC='<?=$SITEURL."images/xl2.jpg"?>'
VALUE ="Open in Excel" ALT="Open in Excel" NAME="assign"></
form>
Looks good so far, except for the short open tags (<?= ...?>). You
should avoid them and use <?php echo ...?instead. Short open tags
are highly unreliable and will be turned off by default in PHP 6.
>How do you test for the button click? Maybe "assign" is fine?
if ($_POST('assign')== 'Open in Excel'
I tried
if ($_POST['assign']!='Open in Excel'){
and it doesn't work because it is an image not a button.
Now we're getting somewhere. Image buttons can be tricky. The browser
doesn't just submit its name or value, but the coordinates at which the
button was "hit" by the mouse or 0, 0 if the button was triggered some
other way.

In your case after the submit the $_POST array should contain the two
entries 'assign_x' and 'assign_y' (the browser sends them as 'assign.x'
and 'assign.y', but PHP turns the dots into underscores for technical
reasons). However, it would not contain an entry with the value "Open in
Excel", so you can't test for that. Instead you could test if 'assign_x'
is there to see if this particular button was pressed. This should work
reliable across various browsers.

HTH
Micha
Jul 28 '08 #11
Luuk schreef:
>
but, u should use the 'elseif' in these sort of cases:

if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}

Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}

But that is of course a private opinion (mine).

Regards,
Erwin Moller
Jul 29 '08 #12
..oO(Erwin Moller)
>Luuk schreef:
>>
but, u should use the 'elseif' in these sort of cases:

if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}


Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
With proper indentation and curly braces as above it's pretty clear to
me. It prevents too deep nesting and keeps the code left.
>I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}

But that is of course a private opinion (mine).
ACK, it's more or less just personal preference. In this case I would
probably even drop the if-else and use a switch instead.

Micha
Jul 29 '08 #13
Jensen Somers wrote:
Erwin Moller wrote:
>Luuk schreef:
>>>
but, u should use the 'elseif' in these sort of cases:

if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}


Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}

But that is of course a private opinion (mine).

Regards,
Erwin Moller

When dealing with a lot of different conditions this can get really
bloated.

if (a == 1) {
do_1();
} else {
if ((a == 2) && (b != 1)) {
do_2();
} else {
if ((a == 2) && (b == 1)) {
do_3();
} else {
if (a == 3) {
do_4();
} else {
do_5();
}
}
}
}

I find this less readable than using 'elseif'. When looking at it it
just seems to be more complex than it actually is.

if (a == 1) {
do_1();
}
elseif ((a == 2) && (b != 1)) {
do_2();
}
elseif ((a == 2) && (b == 1)) {
do_3();
}
elseif (a == 3) {
do_4();
}
else {
do_5();
}

However, I find it is better to avoid mixing different checks within the
same conditional sequence.

if (a == 1) {
do_1();
}
elseif (b == 2) {
do_2();
}

In this case I would add all the checks related to 'b' inside an 'else'
block.
I would prefer this written as:

if (a == 1) {
do_1();
} elseif (a == 2) {
if (b == 1) {
do_3();
} else {
do_2();
}
} elseif (a == 3) {
do_4();
} else {
do_5();
}
Jul 29 '08 #14
sheldonlg wrote:
Jensen Somers wrote:
>Erwin Moller wrote:
>>Luuk schreef:
but, u should use the 'elseif' in these sort of cases:

if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}

Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}

But that is of course a private opinion (mine).

Regards,
Erwin Moller

When dealing with a lot of different conditions this can get really
bloated.

if (a == 1) {
do_1();
} else {
if ((a == 2) && (b != 1)) {
do_2();
} else {
if ((a == 2) && (b == 1)) {
do_3();
} else {
if (a == 3) {
do_4();
} else {
do_5();
}
}
}
}

I find this less readable than using 'elseif'. When looking at it it
just seems to be more complex than it actually is.

if (a == 1) {
do_1();
}
elseif ((a == 2) && (b != 1)) {
do_2();
}
elseif ((a == 2) && (b == 1)) {
do_3();
}
elseif (a == 3) {
do_4();
}
else {
do_5();
}

However, I find it is better to avoid mixing different checks within
the same conditional sequence.

if (a == 1) {
do_1();
}
elseif (b == 2) {
do_2();
}

In this case I would add all the checks related to 'b' inside an
'else' block.

I would prefer this written as:

if (a == 1) {
do_1();
} elseif (a == 2) {
if (b == 1) {
do_3();
} else {
do_2();
}
} elseif (a == 3) {
do_4();
} else {
do_5();
}
I would rather have:

switch ($a) {
case 1:
do_1();
break;
case 2:
if ($b == 1)
do_3();
else
do_2();
break;
case 3:
do_4();
break;
default:
do_5();
}
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 29 '08 #15
Jerry Stuckle <js*******@attglobal.netwrote:
: I would rather have:

: switch ($a) {
: case 1:
: do_1();
: break;
: case 2:
: if ($b == 1)
: do_3();
: else
: do_2();
: break;
: case 3:
: do_4();
: break;
: default:
: do_5();
: }

Thank you. I can read it. --thelma

Jul 29 '08 #16
Jerry Stuckle schreef:
sheldonlg wrote:
>Jensen Somers wrote:
>>Erwin Moller wrote:
Luuk schreef:

>
but, u should use the 'elseif' in these sort of cases:
>
if (a==1){
do_a
}
elseif (a==2){
do_b
}
else {
do_c
}
>
>

Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}

But that is of course a private opinion (mine).

Regards,
Erwin Moller

When dealing with a lot of different conditions this can get really
bloated.

if (a == 1) {
do_1();
} else {
if ((a == 2) && (b != 1)) {
do_2();
} else {
if ((a == 2) && (b == 1)) {
do_3();
} else {
if (a == 3) {
do_4();
} else {
do_5();
}
}
}
}

I find this less readable than using 'elseif'. When looking at it it
just seems to be more complex than it actually is.

if (a == 1) {
do_1();
}
elseif ((a == 2) && (b != 1)) {
do_2();
}
elseif ((a == 2) && (b == 1)) {
do_3();
}
elseif (a == 3) {
do_4();
}
else {
do_5();
}

However, I find it is better to avoid mixing different checks within
the same conditional sequence.

if (a == 1) {
do_1();
}
elseif (b == 2) {
do_2();
}

In this case I would add all the checks related to 'b' inside an
'else' block.

I would prefer this written as:

if (a == 1) {
do_1();
} elseif (a == 2) {
if (b == 1) {
do_3();
} else {
do_2();
}
} elseif (a == 3) {
do_4();
} else {
do_5();
}

I would rather have:

switch ($a) {
case 1:
do_1();
break;
case 2:
if ($b == 1)
do_3();
else
do_2();
break;
case 3:
do_4();
break;
default:
do_5();
}


switch ($a) {
case 1:
do_1();
break;
case 2:
switch ($b) {
case 1:
do_3();
break;
default:
do_2();
break;
}
case 3:
do_4();
break;
default:
do_5();
}
might become unreadible again... ;-)
so, in the end its also personal preferences, as Erwin wrote.

--
Luuk
Jul 29 '08 #17
Luuk wrote:
Jerry Stuckle schreef:
>sheldonlg wrote:
>>Jensen Somers wrote:
Erwin Moller wrote:
Luuk schreef:
>
>>
>but, u should use the 'elseif' in these sort of cases:
>>
> if (a==1){
> do_a
> }
> elseif (a==2){
> do_b
> }
> else {
> do_c
> }
>>
>>
>
Not 'should', but 'can'.
I think elseif is much unclearer that using simple blocks with only
if/the/else.
Personally, I always must read such codeblocks 2 times before
understanding where the 'else' belongs to. ;-)
I find this clearer code:
if (a==1){
do_a
} else {
if (a==2){
do_b
} else {
do_c
}
}
>
But that is of course a private opinion (mine).
>
Regards,
Erwin Moller

When dealing with a lot of different conditions this can get really
bloated.

if (a == 1) {
do_1();
} else {
if ((a == 2) && (b != 1)) {
do_2();
} else {
if ((a == 2) && (b == 1)) {
do_3();
} else {
if (a == 3) {
do_4();
} else {
do_5();
}
}
}
}

I find this less readable than using 'elseif'. When looking at it it
just seems to be more complex than it actually is.

if (a == 1) {
do_1();
}
elseif ((a == 2) && (b != 1)) {
do_2();
}
elseif ((a == 2) && (b == 1)) {
do_3();
}
elseif (a == 3) {
do_4();
}
else {
do_5();
}

However, I find it is better to avoid mixing different checks within
the same conditional sequence.

if (a == 1) {
do_1();
}
elseif (b == 2) {
do_2();
}

In this case I would add all the checks related to 'b' inside an
'else' block.
I would prefer this written as:

if (a == 1) {
do_1();
} elseif (a == 2) {
if (b == 1) {
do_3();
} else {
do_2();
}
} elseif (a == 3) {
do_4();
} else {
do_5();
}

I would rather have:

switch ($a) {
case 1:
do_1();
break;
case 2:
if ($b == 1)
do_3();
else
do_2();
break;
case 3:
do_4();
break;
default:
do_5();
}



switch ($a) {
case 1:
do_1();
break;
case 2:
switch ($b) {
case 1:
do_3();
break;
default:
do_2();
break;
}
case 3:
do_4();
break;
default:
do_5();
}
might become unreadible again... ;-)
so, in the end its also personal preferences, as Erwin wrote.
I wouldn't do a switch on $b when all you have is a match/no match
check. if is much more applicable here.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 29 '08 #18

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

Similar topics

8
by: Craig | last post by:
I want to compare several items and if they are all equal then do this...otherwise do this...see example below... If (a = a) AND (b = b) AND (c = c) AND (d = d) Then ..Code.. Else ..Code.....
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
12
by: Roman Töngi | last post by:
In c++ there does not exist an if-statement as for example in Visual Basic, does it? //VB-analogy: if (cond.) statement; else if (cond.) statement; else statement;
9
by: Barton | last post by:
Hello, I just made to move to ASP. I have been developing in PHP the past two years. I must say that I'm a little disappointed in the quality of the beginners tutorials. They don't go further...
3
by: Jules | last post by:
Just trying to display different wording depending on reference put in. Got it to work ok when it was just ABC then 123, otherwise 789, but now have to add a second IF and am getting errors. Could...
3
by: divya | last post by:
Hiii, Please read the following piece of code:- function SendToWebServer1(sendto) //sendto string contains a URL { if (document.form1.txtbookedby.value == "") { alert('your name field...
6
by: Sonnich | last post by:
this is probably an old topic: if(a==1) if(b==2) echo "a is 1 and b is 2"; else // what happens here? echo "a is 1 and b is not 2"; The question is, where the else will react too. Usually...
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...
10
by: arcticool | last post by:
I was just surprised to find that "Else if" is not required in the code bit below. Apparently "If" and "Else if" are used interchangeably. Please correct me if I'm wrong, but it appears "Else" is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.