PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jbdphp
Forum Newbie
Posts: 6 Joined: Mon Sep 02, 2002 4:53 pm
Post
by jbdphp » Tue Sep 10, 2002 11:46 pm
I am having problems with my
ELSEIF statement (it isn't printing what it should when $sid is != to $sid). The
IF is working fine but here check it out (thanks in advance):
Code: Select all
<?php
if($sid == $sid):
$sql = mysql_query("SELECT * FROM shows WHERE sid = '$sid' ORDER BY sid DESC LIMIT 1");
while($row=mysql_fetch_array($sql)) {
$sid = $rowї"sid"];
$sdfdb = $rowї"sdfdb"];
$show_date = $rowї"show_date"];
$bandaide_band = $rowї"bandaide_band"];
$other_bands = $rowї"other_bands"];
$venue = $rowї"venue"];
$city = $rowї"city"];
$state = $rowї"state"];
$time = $rowї"time"];
$price = $rowї"price"];
echo "<table width="100%" border="0" align="center">";
echo "<tr><td width="30%">Date</td><td width="30%">$show_date</td></tr>";
echo "<tr><td width="30%">Band+aide band</td><td width="30%">$bandaide_band</td></tr>";
echo "<tr><td width="30%">Other bands</td><td width="30%">$other_bands</td></tr>";
echo "<tr><td width="30%">Venue</td><td width="30%">$venue</td></tr>";
echo "<tr><td width="30%">City</td><td width="30%">$city</td></tr>";
echo "<tr><td width="30%">State</td><td width="30%">$state</td></tr>";
echo "<tr><td width="30%">Time</td><td width="30%">$time</td></tr>";
echo "<tr><td width="30%">Price</td><td width="30%">$price</td></tr>";
}
?>
<tr><td width="30%"></td><td width="30%"><br><a href="javascript:;" onClick="printshow('printshow.php?sid=<?php echo "$sid" ?>','','scrollbars=yes,width=400,height=300')">Print
Show Info</a></td></tr>
</table>
<?
elseif($sid != $sid):
echo "<tr><td>Show ID is invalid. Go Back.</td></tr>";
echo "</table>";
endif;
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Sep 11, 2002 12:32 am
if($sid == $sid):
you could write "if(TRUE): ... elseif(FALSE):" as well
A variable is always (?) equal to itself and never unequal to itself.
What do you want to achieve or is it a typo?
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Wed Sep 11, 2002 1:00 am
OK, if you are using ELSEIF shoudn't there be ELSE to? Because all the example in PHP manual has IF and ELSEIF and ELSE.
Last edited by
Takuma on Wed Sep 11, 2002 1:15 am, edited 1 time in total.
dusty
Forum Contributor
Posts: 122 Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA
Post
by dusty » Wed Sep 11, 2002 1:10 am
no takuma.
Like volka said, a variable is going to be equal to itself..
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Wed Sep 11, 2002 5:59 am
What if it is a different type, === would be a better test for equality
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Sep 11, 2002 6:08 am
But how can the same variable be of two different types at the same time?
Code: Select all
<?php
$sid = 2;
if ($sid === $sid) {
echo 'of course it does!';
} else {
echo 'wtf?';
}
?>
Doing
is like writing
so it's fairly pointless 2 will always be exactly equal to 2.
If you change the $sid value based on something else have an $old_sid value to compare against in the conditional statement:
Code: Select all
$sid = 2;
$old_sid = $sid;
$sid = 15;
if ($sid == $old_sid) {
// Do something
} else {
// Do something else
}
But once again, as Volka asked, what are you trying to achieve, what are you trying to compare?
Mac
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Wed Sep 11, 2002 7:53 am
dusty wrote: no takuma.
Like volka said, a variable is going to be equal to itself..
That's a point but I'm also pinting another point!
dusty
Forum Contributor
Posts: 122 Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA
Post
by dusty » Wed Sep 11, 2002 10:28 am
Actually my post was saying no to your previous post saying that he forgot to include a } which isn't needed the way he is setting up his statements, but you seem to have edited that post.. The other part of my post was just saying the problem is with $sid == $sid and the rest of the code looks fine.
BDKR
DevNet Resident
Posts: 1207 Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:
Post
by BDKR » Wed Sep 11, 2002 5:08 pm
Perhaps I'm stupid or behind the times or something, but what's this about?
In particular, the colon at the end of it? That actually works?
Cheers,
BDKR
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Thu Sep 12, 2002 2:24 am
Yesp but if you are going to use ELSEIF don't you have to have ELSE as well as ELSEIF?
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Thu Sep 12, 2002 2:27 am
No. You only need an else if you want something to happen if none of the conditions in the if and elseif's are met. You can just have an if or you can have an if and some elseifs or you can have an if some elseifs and an else or you can have an if and an else... It all depends what you are trying to do.
Mac
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Sep 12, 2002 2:55 am
it's simply a more convenient form of
Code: Select all
if(cond1) { }
else {
if (cond2)
...
... }some languages have it, some don't. But in then (like in C) it's only "a blank away"
Code: Select all
if(cond1) { }
else if (cond2) {}