Forum Moderators: coopster
Hope you are all well :)
I know nothing about php but have been trying to do the odd thing.
I have a table (in template.html) that has php echo statements loading from codes.php
The only problem I have is that I would like the TR not to show if there is nothing in the php echo.
Is this possible.
To get what I mean see my code:
My php code:
$atitle1 = "Blurb 1";
$acode1 = "More blurb 1";
$atitle2 = "";
$acode2 = "";
I wont always have things in $atitle2 but don't want to have to change the code in template.html everytime.
My html code:
<table width=500 border=1 bordercolor="#02679A" cellpadding=7 cellspacing=0><tr bgcolor="#02679A"><td align=center valign=center><font color=white><b>Title</b></font></td><td align=center valign=center><font color=white><b>Description </b></font></td></tr>
<tr><td><?php echo "$atitle1"; ?></td><td><?php echo "$acode1"; ?></td></tr>
<tr><td><?php echo "$atitle2"; ?></td><td><?php echo "$acode2"; ?></td></tr>
<tr><td><?php echo "$atitle3"; ?></td><td><?php echo "$acode3"; ?></td></tr>
</table>
So is there any way I can have php (or some other script) not show the tr with nothing in? I need this because the tables arent appearing correctly without anything in.
Please please please please give me any help you can.
Emma
//if the atitle is blank
if($atitle1 == ""){
//we don't do anything
}
//otherwise it equals something
else{
echo("<tr><td>{$atitle2}</td></tr>");
}
if you want the value of $atitle2 there then leave the squiggilies. If you want the actual text $atitle2 then remove the squiggilies. Let me know if I can help anymore.
<?php
echo "<table width=500 border=1 bordercolor=\"#02679A\" cellpadding=7 cellspacing=0><tr bgcolor=\"#02679A\"><td align=center valign=center><font color=white><b>Title</b></font></td><td align=center valign=center><font color=white><b>Description </b></font></td></tr>";
echo "<tr><td>$atitle1</td><td>$acode1</td></tr>";
//Note the use of the "IF" operator here
IF ($atitle2==NULL)
{
echo "<tr><td>$atitle2</td><td><$acode2</td></tr>";
}
echo "<tr><td>$atitle3</td><td>$acode3</td></tr></table>";
?>
Then just include the above in your include file along with your variables.
HTH!
</head>
<body>
<table>
<?php require_once("test2.php"); ?>
</table>
</body>
</html>
this is test2.php
<?php
for($i = 1; $i <= 10; $i++){
//the % function returns the remainder therefore if the
//remainder is 0 then the row is even because anything divided
//by 2 with a remainder of 0 is even otherwise it is odd
if(($i % 2) == 0){
echo("<tr><td>even row {$i}</td></tr>");
}//if
else{
echo("<tr><td>odd row {$i}</td></tr>");
}//else
}//for
?>
in your case echo your table tags when your variables are not null