JDMnet Forums
Not logged in [Login - Register]
Go To Bottom

Printable Version | Subscribe | Add to Favorites  
Author: Subject: php: "else if" problem
lsdmw123
Junior Member
**




Posts: 46
Registered: 3/21/2005
Member Is Offline

Mood: No Mood

[*] posted on 3/22/2005 at 02:41 PM
php: "else if" problem


Please see my problem below in PHP code :

--------------------------------------------------------------------------------

<?php
echo $month, $day, $year, $month2, $day2, $year2; // these are ok-normal values from web form
if ( ! @checkdate($month,$day,$year) ) {
echo "this operate till here"; // include_once ("normaldays.php"); @ // wrongpickupdate.htm
} else if ( ! @checkdate($month2,$day2,$year2) ) {
include_once ("wrongdropoffdate.htm");
} else if ( $tsp < $tsnow ) { // "$tsp"=time stamp pickup date
include_once ("wrongpickupdate.htm"); // include_once ("normaldays.php"); // wrongpickupdate.htm
} else if ( $tsp >= $tsd ) { // "$tsd"=time stamp drop off date
include_once ("wrongpickupdate.htm");
} else if ( $days >= 60 ) { // "$days" var come from "$tsd" & "$tsp"
include_once ("manydays.htm");
} else if ( $days <= 2 ) {
include_once ("fewdays.htm");
} else {
include_once ("normaldays.php");
}

?>

--------------------------------------------------------------------------------

problem

1-executes first statement what ever vars are
2-if no "!" to first statement , executes second statement
3-if no "!" to first & second statement, executes first include_once() statement meaning :
} else if ( $tsp < $tsnow ) {
include_once ("wrongpickupdate.htm");
}
whatever values of $tsp & $tsnow are .

well WHERE THE PROBLEM IS ?
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1771
remmy
Junior Member
**




Posts: 5
Registered: 12/12/2003
Member Is Offline

Mood: No Mood

[*] posted on 3/22/2005 at 03:12 PM


Sorry but I have no idea what you're asking. Maybe you could show us or something?
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1772
lsdmw123
Junior Member
**




Posts: 46
Registered: 3/21/2005
Member Is Offline

Mood: No Mood

[*] posted on 3/23/2005 at 06:47 AM


what ever variable values are, script executes 1-,2-,3-, below:
problem

1-executes first statement what ever vars are
2-if no "!" to first statement , executes second statement
3-if no "!" to first & second statement, executes first include_once() statement meaning :
} else if ( $tsp < $tsnow ) {
include_once ("wrongpickupdate.htm");
}
whatever values of $tsp & $tsnow are .

well WHERE THE PROBLEM IS ?
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1773
lsdmw123
Junior Member
**




Posts: 46
Registered: 3/21/2005
Member Is Offline

Mood: No Mood

[*] posted on 3/23/2005 at 06:27 PM


the precedence / sequence

has any relationship with:

1-calculations between variables & constants
2-built-in functions
3-the NOT decision: !
4-or any other ?

this because in my script executes the third "else if" conditional if no met the second or third BUT in case of any met of fourth or fifth "else if" conditional ?
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1775
lsdmw123
Junior Member
**




Posts: 46
Registered: 3/21/2005
Member Is Offline

Mood: No Mood

[*] posted on 3/29/2005 at 07:44 AM


wrong decisions from an "else if" in php can you check ?
=========================================================
My web server uses PHP 4.3.10 well the previous code I have posted may run on this ? "elseif" differs from "else if" ?

The Script(I make some modifications) start at(web form):
http://paphoscarhire.com/php/a1.php
go to(decision php script):
http://paphoscarhire.com/php/b1.php
Well you may see that problem is firstly the: else-if iteration[at http://paphoscarhire.com/php/b1.php ] make wrong decisions , can you check where is the mistake ?
Variable values appear on screen prior/after the "else if" .

=================script======b1.php=====

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<?php
// [Censored]ignments
echo "this operate till here";
print "this operate till here";
$Locationp = $_POST['pickUpLocation'];
$Locationd = $_POST['dropOffLocation'];
$day = $_POST['pickUpDay'];
$day2 = $_POST['dropOffDay'];
$month = $_POST['pickUpMonth'];
$month2 = $_POST['dropOffMonth'];
$year = $_POST['pickUpYear'];
$year2 = $_POST['dropOffYear'];
$hour = $_POST['pickUpTimeHour'];
$hour2 = $_POST['dropOffTimeHour'];
$min = $_POST['pickUpTimeMinute'];
$min2 = $_POST['dropOffTimeMinute'];
$s = 0;
$s2 = 0;
$tsnow = mktime();
$tsm = mktime(0, 0, 0, 3, 16, 2005);
$tsh = mktime(0, 0, 0, 7, 1, 2005);
$tsl = mktime(0, 0, 0, 11, 1, 2005);
$tsm2006 = mktime(0, 0, 0, 3, 16, 2006);
$tsp = mktime($hour, $min, 0, $month, $day, $year);
$tsd = mktime($hour2, $min2, 0, $month2, $day2, $year2);
$ts2005 = mktime(0, 0, 0, 1, 1, 2005);
$ts2006 = mktime(0, 0, 0, 1, 1, 2006);
$ts2007 = mktime(0, 0, 0, 1, 1, 2007);
$datep = date("H:i l F dS, Y", $tsp);
$dated = date("H:i l F dS, Y", $tsd); // check this

// $days
$x = ($tsd - $tsp)/(24*60*60);
$z = ($tsd - $tsp)%(24*60*60);
$y = floor($x);

if ($z >= (2*60*60)) {
$days = $y + 1;
} else {
$days = $y;
}

// date errors & total days errors
echo $month, $day, $year, $month2, $day2, $year2;

if (! @checkdate($month, $day, $year)) {
echo "first checkdate-wrongpickupdate.htm";
} elseif (! @checkdate($month2, $day2, $year2)) {
echo "second checkdate-wrongdropoffdate.htm";
} else if ( $tsp < time() ) {
echo "tsp-tsnow-wrongpickupdate.htm";
} else if ($tsp > $tsd) {
echo "tsp-tsd-wrongpickupdate.htm";
} else if ( $days >= 60 ) {
echo "60-manydays.htm";
} else if ( $days <= 2 ) {
echo "2-fewdays.htm";
} else {
echo "true normaldays.php";
}
echo "";
echo $month, $day, $year, $month2, $day2, $year2;


?>
</body>

</html>
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1789
Jonathon
JDMnet President
*********




Posts: 833
Registered: 12/9/2001
Location: Tuscaloosa, AL; USA
Member Is Offline

Mood: No Mood

[*] posted on 3/30/2005 at 12:24 AM


OK; one thing I see - and I think yuo are asking about...

Yopu asking weather you can use "elseif" or "else if" to do statements/etc.

Well, only the following three are "valid" when it comes to "if"/"elseif"/"else"...

if for the firsdt statement...

elseif for any following statements...

else for the final/default choice/result.

So, an example would be :


Code:

if ( $pg == '1' ) {
echo 'Page One';
} elseif ( $pg == '2' ) {
echo 'Page Two';
} else {
echo 'No Page Selected';
}


Hope that helps some.

I think that will also fix your problem you are having.

And sorry to took so long to relaize what you were asking about.


-Jonathon




.:/ JDMnet President | www.jdmnet.org

The question is not why; it is, do you want to know?
-- Arami Nao

ACTA NON VERBA
View user's profile Visit user's homepage View All Posts By User U2U Member This user has MSN Messenger
  http://jdmnet.org/forums/thread613-pg1.htm#pid1790
Jonathon
JDMnet President
*********




Posts: 833
Registered: 12/9/2001
Location: Tuscaloosa, AL; USA
Member Is Offline

Mood: No Mood

[*] posted on 3/30/2005 at 12:37 AM


Another thing I have notice; you seem to be wanting to echo/include a file...

You don't use a command/line like :

- echo "too_many_days.html"

If you are wanting just the contents of a page to diaplys; say if you have a web page that just said "To many days selected" (or what ever) then you would need to use this line instead :

- include 'too_many_days.html';

That would automaticaly display the contents of the file [what i maean is - it will display any text that is supposed to show -- it won't show the<html> tags or anything like that].

One thing to keep in mind however; if the page you wanna "include" is a PHP file that is supposed to use a certain "varible" [like $day] then you would need to do something like this line instead :

- include "too_many_days.php";

That should work fine; make sure of course that you use proper PHP coding.


Another thing...

You may notice I'm using single quotes [ ' ' ] in some parts and double quotes [ " " ] in others. There is a reason for this.

Firstly, if you are wanting to just "echo" some basic text; with no varibles; then all you ould have to do is something like echo 'hello world';.

But, if there is a vairble in it you would need to use double quotes.


-Jonathon




.:/ JDMnet President | www.jdmnet.org

The question is not why; it is, do you want to know?
-- Arami Nao

ACTA NON VERBA
View user's profile Visit user's homepage View All Posts By User U2U Member This user has MSN Messenger
  http://jdmnet.org/forums/thread613-pg1.htm#pid1792
lsdmw123
Junior Member
**




Posts: 46
Registered: 3/21/2005
Member Is Offline

Mood: No Mood

[*] posted on 3/30/2005 at 03:49 AM


In include() or include_once() commands I must use single'' or double "" quotes ?
What about parenthesis () ?
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid1793
Jonathon
JDMnet President
*********




Posts: 833
Registered: 12/9/2001
Location: Tuscaloosa, AL; USA
Member Is Offline

Mood: No Mood

[*] posted on 3/30/2005 at 09:55 AM


Quote:
Originally posted by lsdmw123
In include() or include_once() commands I must use single'' or double "" quotes ?
What about parenthesis () ?



Well; there are several ways to do it.

For starters; if all you want to do is include the content of an HTML/HTM page -- and thats all -- you can use either of the following ways :

- include 'hello_text.html';
- include "hello_text.html";
- include ('hello_text.html');
- include ("hello_text.html");

That is just a matter of preference. Persoanly I think it's more clean looking using the parenthesis around what you are including. And, they say that you should use single quotes where possible cause they are slightly fatser to process then double quotes.

Butm you would need a real large amount of code to realy notice a difference however.

But, say if you are wanting to inculde a page that is based on a varible " $day ", and that varible needed to be within the "include" call. You would need to do one of the following :

- include "hello_$day.html";
- include ("hello_text.html");

Hope that helps some.


-Jonathon




.:/ JDMnet President | www.jdmnet.org

The question is not why; it is, do you want to know?
-- Arami Nao

ACTA NON VERBA
View user's profile Visit user's homepage View All Posts By User U2U Member This user has MSN Messenger
  http://jdmnet.org/forums/thread613-pg1.htm#pid1795
Mayuri21
Newbie
*




Posts: 1
Registered: 10/20/2009
Member Is Offline


[*] posted on 10/20/2009 at 06:32 AM


This because in my script executes the third "else if" conditional if no met the second or third BUT in case of any met of fourth or fifth "else if" conditional.


Regards

Mayuri

____
dossier surendettement
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid2024
proximityinfotech3
Junior Member
**




Posts: 2
Registered: 7/23/2010
Member Is Offline


[*] posted on 7/23/2010 at 06:11 AM


Link Building| Link Building Services
View user's profile View All Posts By User U2U Member
  http://jdmnet.org/forums/thread613-pg1.htm#pid2026

  Go To Top

Powered by XMB
Developed By The XMB Group © 2001-2008
[Queries: 19] [PHP: 98.9% - SQL: 1.1%]