Jump to content

If and else statment inside a table


primefalcon

Recommended Posts

I'm trying to apply and else and if statement in the following section as you see, and I have tried numerous things, and just cant get the thing to actually work.Could someone please advise how I can get the if and else statement below to actually work, thank you, as you can pr9obaly see I'n extract9iing info from a mysql database and try to make the content change, whether there's a supplied url or not

<?phpecho "<table class='fore' border='1' bordercolor='white' width='100%' align='center'>";echo "<tr>				<td><center><b class='thead'>Character name</b></center></td>				<td><center><b class='thead'>Character Site/Blog URL</b></center></td>				<td><center><b class='thead'>Player's Comments</b></center></td>				</tr>";while ($row = mysql_fetch_array($result))	{		extract($row);			echo "<tr>\n					<td width='120' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$name'>$name</a></b></td>\n										<td width='50' valign='top'><a href='$url' target='_self'><b class='tlink'>"																						if ($url = = null)					{					echo "No Url Supplied";					}										else										{					echo "$name Website"; 					}																																		"</b></a></td>\n										<td width='*' valign='top'><b class='tdes'>$description</b></td>\n					</tr>\n";							echo "<tr><td colspan='3'></td></tr>\n";			}		echo "</table>\n";	?>

Link to comment
Share on other sites

This is the syntax of an if-else statement:if (expression){ //statements to execute if the expression is true}else{ //statements to execute if the expression is false}The expression can be any valid PHP expression, meaning anything that will evaluate to a value. An assignment statement, a function call, a logical comparison, or even just a single variable or constant are all expressions that you can use. Here are the operators you can use for comparison:http://www.php.net/manual/en/language.oper....comparison.phpThere is a == operator and a === operator, but it is not syntactically valid to use = =, with a space. That is two assignment operators, not one comparison operator.Also, if you want to check if a variable such as $url is empty or blank, instead of null use one of these:

if ($url == "")if (empty($url))

You also have your if statement in the middle of a giant echo. You need to end the echo, then do the if, then start another echo.

Link to comment
Share on other sites

Ok I've modified my code to this below:

<?phpecho "<table class='fore' border='1' bordercolor='white' width='100%' align='center'>";echo "<tr><td><center><b class='thead'>Character name</b></center></td><td><center><b class='thead'>Character Site/Blog URL</b></center></td><td><center><b class='thead'>Player's Comments</b></center></td></tr>";while ($row = mysql_fetch_array($result)){extract($row);echo "<tr>\n<td width='120' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$name'>$name</a></b></td>\n<td width='50' valign='top'> " /*echo ended here *//*start of else funtion */if (empty($url)){echo "No Url Supplied";}else{echo "<a href=$url target='_self'><b class='tlink'>$name Website";}/* end of fuction */echo "</b></a></td>\n<td width='*' valign='top'><b class='tdes'>$description</b></td>\n</tr>\n";echo "<tr><td colspan='3'></td></tr>\n";}echo "</table>\n";?>

in the broser I am getting this error:Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/content/m/e/t/metaconcert/html/main site/sections/registry/registry.php on line 171line 171 also happens to be:if (empty($url))so I'm not exactly sure whats going on

Link to comment
Share on other sites

Statements in PHP need to end with a semicolon, so the first echo never ended. That's why it's complaining about seeing the IF, it is expecting data to print instead of a control structure. Add a semicolon:

<td width='50' valign='top'> "; /*echo ended here */						 	 ^that one

Link to comment
Share on other sites

You have put in a physical line break here:

echo "<tr>\n<td width='120' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$name'>$name</a></b></td>\n<td width='50' valign='top'> " /*echo ended here */

PHP doesnt like em. So just use <br> tags or /n but not actual line breaks. The result should look like this:

echo "<tr><td width='120' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$name'>$name</a></b></td><td width='50' valign='top'> " /*echo ended here */

You should not need ine breaks in the table tag anyway unless you want a space. If so just pop in some <br/> tags.

Link to comment
Share on other sites

Thank you very much, and dang it I I didn't even notice the missing semicolon.Thank you so much to both of you :-)now all I need to figure out is how to split up the results of difference pages and have links to each of the pages, I'm thinking that probably another function call so off I go to do more study, though if someone can just give me a point where I should be looking that would be cool too :-)edit: btw the null does work since it is accessing a mysql database

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...