unexpected T_IF Issues

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

User avatar
idevlin
Forum Commoner
Posts: 78
Joined: Tue Jun 26, 2007 1:10 pm
Location: Cambridge, UK

Post by idevlin »

ghadacr wrote:

Code: Select all

if  ($row['Confirmed' ] > 0)  { 
			echo "Hello"; 
			} else { 
			   echo '<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update';	   
			   }
Erm yes, and then try and see if it works?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Hey, nothing works....Hmmm i got a slight feeling something else is stopping this from working....
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

The new problem know is that the code is not outputting the desired hyperlink if the if statement is conditioned to true, instead it just ouputs a blank...

Code: Select all

while ($row = mssql_fetch_array($result))
		
{ 
    echo '<tr>';
	echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
   
	if  ($row['Confirmed' ] == 1)  { 
			'<td bgcolor="#FFFF00"><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';  } else { 
			   echo '<td><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';	   
			   
	
    echo '</tr>'; 



}


 }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's no echo associated with the statement(s) in the true side of the if.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Thanks, that got it working, its always good to have another pair of eyes.... :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Would be easier to see the problem if the code was properly indented

Code: Select all

<?php
while ( $row=mssql_fetch_array($result) ) {
  echo '<tr>';
  echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';
  echo '<td>' . $row['HotelName' ] . '</td>';
  echo '<td>' . $row['RoomType' ] . '</td>';
  echo '<td>' . $row['AvailableFrom' ] . '</td>';
  echo '<td>' . $row['AvailableTo' ] . '</td>';
  echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
  echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
  echo '<td>' . $row['Notes' ] . '</td>';

  if  ($row['Confirmed' ] == 1)  {
    '<td bgcolor="#FFFF00"><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';
  }
  else {
    echo '<td><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />
      Select  ' . $row['RoomType'] .' to update</td>';    
    echo '</tr>';
  }
}
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Advice taken on board:

Just another problem the other if statment is not outputting the desired colour, it just ouputs

Code: Select all

$colour

Code: Select all

while ($row = mssql_fetch_array($result))
		
{ 
$colour="";
if($row['Confirmed' ] == 1)  { 
echo $colour == "bgcolor=#FFFF00";

}else{
echo $colour == "bgcolor=";

    echo '<tr>';
	echo '<td' . $colour .'><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td' . $colour .'>' . $row['HotelName' ] . '</td>'; 
	echo '<td'.  $colour .'>' . $row['RoomType' ] . '</td>'; 
	echo '<td' . $colour . '>' . $row['AvailableFrom' ] . '</td>';
	echo '<td' . $colour . '>' . $row['AvailableTo' ] . '</td>';
	echo '<td' . $colour .'><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td' . $colour .'><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td $colour>' . $row['Notes' ] . '</td>';
   
	if  ($row['Confirmed' ] == 1)  { 
			echo '<td' . $colour .'><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';  } else { 
			   echo '<td' . $colour .'><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';	   
			   } 
	
    echo '</tr>'; 
}


}
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

ghadacr wrote:

Code: Select all

echo '<td $colour>' . $row['Notes' ] . '</td>';
You've written it correctly everywhere but there.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

initially i saw the mistake, then i changed it to this:

Code: Select all

<?php 

	
while ($row = mssql_fetch_array($result))
		
{ 
$colour="";
if($row['Confirmed' ] == 1)  { 
echo $colour == "bgcolor=#FFFF00";

}else{
echo $colour == "bgcolor=#990033";

    echo '<tr>';
	echo '<td' . $colour .'><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td' . $colour .'>' . $row['HotelName' ] . '</td>'; 
	echo '<td'.  $colour .'>' . $row['RoomType' ] . '</td>'; 
	echo '<td' . $colour . '>' . $row['AvailableFrom' ] . '</td>';
	echo '<td' . $colour . '>' . $row['AvailableTo' ] . '</td>';
	echo '<td' . $colour .'><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td' . $colour .'><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td' . $colour .'>' . $row['Notes' ] . '</td>';
   
	if  ($row['Confirmed' ] == 1)  { 
			echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';  } else { 
			   echo '<td><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';	   
			   } 
	
    echo '</tr>'; 
}


}



?>
Then i was not getting the output:
$colour
now i'm getting nothing, which is strange..Is it my if or else statement ??????
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Probably. If you're if statement is true, absolutely nothing happens. It looks like it'd echo '0.'
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Ok i have revised the code. Now i'm just getting black... i think i'm not constructing the code properly!!!!

I want the colour to print out what ever the if else statement executes, so it could be either $colour1 or $colour2.... Help please..

Code: Select all

while ($row = mssql_fetch_array($result))
		
{ 
$colour1="white";
$colour2="blue";
$colour = $colour2 || $colour1;
if($row['Confirmed' ] == 1)  { 
	echo $colour1 == $colour;
	}

else{
	echo $colour2 == $colour;
}
    echo '<tr bgcolor='.  $colour .'>';
	
    echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td bgcolor='.  $colour .'>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
   
	if  ($row['Confirmed' ] == 1)  { 
			echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">This room has been confirmed, select for more information</a></td>';  } 
	else { 
		echo '<td><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';	   
		} 

    echo '</tr>'; 
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

== tests for equality
= assigns a value
echo prints something

what does
echo $colour1 == $colour;
do?
Please indent and format your code properly.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

This is what i got now

Code: Select all

while ($row = mssql_fetch_array($result))
		
 { 
  	$colour;
  	$colour1="red";
  	$colour2="blue";

if($row['Confirmed' ] == 1)  { 
	echo $colour1($colour);
	}

else{
	echo $colour2($colour);
}
    	echo '<tr bgcolor='.  $colour .'>';
	
    	echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
   
if  ($row['Confirmed' ] == 1)  { 
			echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">This room has been confirmed, select for more information</a></td>';  } 
	else { 
		echo '<td><input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';	   
		} 

    echo '</tr>'; 
}
[/size][/size]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

parentheses?
I thought you wanted to assign a value to the variable $colour?

Please indent and format your code properly.


p.s.: You really should take some basic tutorials.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

[quote="volka"
p.s.: You really should take some basic tutorials.[/quote]

I dont think that is helpful....

I want color to either execute color1 or color2.......
Post Reply