DAMN }else{

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

Post Reply
User avatar
jbdphp
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 4:53 pm

DAMN }else{

Post by jbdphp »

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;
		
	?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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? ;)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

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 »

no takuma.

Like volka said, a variable is going to be equal to itself..
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

What if it is a different type, === would be a better test for equality
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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

Code: Select all

if ($sid == $sid) {
is like writing

Code: Select all

if (2 == 2) {
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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

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! :wink:
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Perhaps I'm stupid or behind the times or something, but what's this about?

Code: Select all

if($sid == $sid):
In particular, the colon at the end of it? That actually works?

Cheers,
BDKR
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

Yes the colon works, it's an alternative syntax.

http://www.php.net/manual/en/control-st ... syntax.php

Code: Select all

if($var == 0 ):
    echo $someThing;
elseif ( $var !=0 ):
    echo $someThingElse;
else:
    echo $catchAll;
endif;   //<  --  note semi - colon on the endif
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Yesp but if you are going to use ELSEIF don't you have to have ELSE as well as ELSEIF?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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) {}
Post Reply