adding <tr> if something is TRUE??

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
atronmania
Forum Newbie
Posts: 5
Joined: Sat Dec 31, 2005 3:37 am

adding <tr> if something is TRUE??

Post by atronmania »

Hi everyone,
lets says i have this:

<table>
<tr>
<td>xyz <?php echo $row['ras1']; ?><span > ;</span>xyz <?php echo $row['ras2']; ?></td>
</tr>
</table>


I want this <tr> to be visible only when $row['ras1']!=""
otherwise it should not echo this TR!!!

any ideas???
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

a simple if statement can be used to accomplish this. replace your current snippet with this:

Code: Select all

<table> 
  <?php
    if ($row['ras1'] != "") {
      echo "<tr>
      <td>xyz {$row['ras1']} <span > ;</span>xyz {$row['ras2']}</td>
      </tr>";
    }
  ?>
</table>
Last edited by jayshields on Sun Jan 01, 2006 8:27 am, edited 1 time in total.
atronmania
Forum Newbie
Posts: 5
Joined: Sat Dec 31, 2005 3:37 am

Post by atronmania »

That easy, ha???? thank you!

is there a tutorial or something to show how to avoid errors for writing the "html code" with "echo"??

I mean what if i'd like to echo something much complex like this:
<a href="../OLD/font/datapc/0-9/5x5dots.zip"><img src="image/0.gif" width="42' height="36" border="0" hspace="6" vspace="5"></a>


And a Happy new year to you all! 2006 is here!! :lol:
IAD
Forum Commoner
Posts: 42
Joined: Wed Dec 28, 2005 12:36 pm
Location: Israel, Soon Canada :)

Post by IAD »

<a href="../OLD/font/datapc/0-9/5x5dots.zip"><img src="image/0.gif" width="42" height="36" border="0" hspace="6" vspace="5"></a>

There's no problem, just instead of "" qoute use ' ' .

here:

Code: Select all

echo '<a href="../OLD/font/datapc/0-9/5x5dots.zip"><img src="image/0.gif" width="42" height="36" border="0" hspace="6" vspace="5"></a> ';
Happy new year..

Jcart | Fixed parse error :0
atronmania
Forum Newbie
Posts: 5
Joined: Sat Dec 31, 2005 3:37 am

Post by atronmania »

awesome!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

sorry i missed the closing curly brace. ive editted my previous post now.
MaNiAC
Forum Newbie
Posts: 20
Joined: Fri Dec 23, 2005 4:20 am

Post by MaNiAC »

Or you could escape it.

Code: Select all

echo "Escape this \" and now i'll add a meal: $meal.. this will work only within double \", you can also do this: ".$meal." see?";
Post Reply