How do I add a style to this output

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
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

How do I add a style to this output

Post by mhouldridge »

Hi,

I would like to add a class to the date output from the following php;

Code: Select all

echo '<span class="standard">';

              echo "<a href='viewasset.php?varl=".$myrow['title']."' class=\"blue8\">".$myrow['title']."</a>";
			  
			  echo "<br> ";
			   
			  echo $myrow['text1'];
			   
			  echo "<br><class=\"blue8\">Postdate: ";
			   
			  echo $myrow['dtime'];

			  echo "<br> ";
			echo "<br> ";
I have already assigned a class in the first echo statement however I need different styles for each row.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I don't see any rows defined. do you mean you want to alternate the the row styles or every third or what?

if you just want to alternate you can do something like this:

Code: Select all

$on = TRUE;
while($row = mysql_fetch_assoc($result))
{
    echo "<tr class=\"".$on ? "class1" : "class2"."\">"; // etc
    $on = !$on;
}
if you want to do more than alternate, take a look at the modulus operator.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I think you misinterpreted (spelling?) him.

He refers to "rows" as echo statement, echo <br>, echo statement, etc, I don't think he wants a table.

This should really be in the client side forum.

To assign style classes just put this <span class="classname">styled text</span>, then to style some other text differently, <span class="otherclassname">differently styled text</span>.

In your code you don't close your span tags, and you also try <class="whatever">, which can't be done.
Post Reply