Page 1 of 1

Parse error: syntax error, unexpected T_IF

Posted: Thu Jun 07, 2007 5:11 am
by ghadacr
I keep getting the above error , i 'm not sure where the error is coming from, any help would be apperciated

Error recieving
Parse error: syntax error, unexpected T_IF

Code: Select all

<?php 
while ($row = mssql_fetch_array($result)) 
{ 
    echo '<tr>'; 
    echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td><input name="DummyRoom" type="hidden" value="' .$rows['DummyRoom']. '" />'. if( $rows['DummyRoom'] == 1 ){echo "Yes" }else { echo "No" } .' </td>'; 
 

} 
?>

Posted: Thu Jun 07, 2007 5:23 am
by dhrosti
semi colon is needed just before the 'if'.

edit: sorry, i didnt realise what you were trying to do. the if statement doesn't have to be in the same line.

eg...

Code: Select all

echo "<td>something";
if (condition) {
  echo "something else";
} else {
  echo "more stuff";
}
echo "</td>";
or you could use .= like...

Code: Select all

$text = "<td>something";
if (condition) {
  $text .= "something else";
} else {
  $text .= "more stuff";
}
$text .= "</td>";

echo $text;

Posted: Thu Jun 07, 2007 5:29 am
by ghadacr
Nice try but that didnt work all i got was
Parse error: syntax error, unexpected ';' in
code:

Code: Select all

while ($row = mssql_fetch_array($result)) 
{ 
    echo '<tr>'; 
    echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td><input name="DummyRoom" type="hidden" value="' .$rows['DummyRoom']. '" />'. ;if( $rows['DummyRoom'] == 1 ){echo "Yes" }else { echo "No" } .' </td>'; 
	echo '<td>' . $row['DummyName' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td>'.$row['HotelID' ] . '<input name=HotelID type=hidden value="'. $row['HotelID']. '"></td>';
	echo '<td>' . $row['Notes' ] . '</td>'; 
    echo '<td><input type="radio" name="HotelRoomID" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>'; 
    echo '</tr>'; 

}

Posted: Thu Jun 07, 2007 5:41 am
by ddragas
error is coming becouse you've puted dot "." in place where it should be

Code: Select all

.$rows['DummyRoom']. '" />'. if( $rows[
here it is

Code: Select all

while ($row = mssql_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['RoomType' ] . "</td>";
    echo "<td><input name=\"DummyRoom\" type=\"hidden\" value=" . $rows['DummyRoom']. " />";
	if( $rows['DummyRoom'] == 1 )
		{
			echo "Yes";
		}
			else
		{
			echo "No";
		}
	echo "</td>";
    echo "<td>" . $row['DummyName' ] . "</td>";
    echo "<td>" . $row['AvailableFrom' ] . "</td>";
    echo "<td>" . $row['AvailableTo' ] . "</td>";
    echo "<td>".$row['HotelID' ] . "<input name=\"HotelID\" type=\"hidden\" value=" . $row['HotelID'] . "></td>";
    echo "<td>" . $row['Notes' ] . "</td>";
    echo "<td><input type=\"radio\" name=\"HotelRoomID\" value=" . $row['HotelRoomID'] . " />";
	echo "Select  " . $row['RoomType'] . " to update</td>";
    echo "</tr>";

}
try to write code in your way, but keep in mind to write it to be more easier to read.

regards ddragas

Posted: Thu Jun 07, 2007 7:14 am
by ghadacr
Thanks for the assitance, that helped just great!!!!!