Forum Moderators: coopster

Message Too Old, No Replies

PHP code help of text formatting

         

smartcard

1:51 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



I have a PHP script giving the information of cars, and following is the code. How can I bold only the labels of the data?

[code]
$ShowInfo = "<table border=0 align=center width=\"100%\">\n\t<tr>\n\t<td width=\"60%\" valign=top><font size=3 face=verdana color=black><b>$a1[VehicleName] $a1[VehicleModel]</b>
<br>Year: $a1[VehicleYear]
<br>Mileage: $a1[mileage] miles
<br>Colour: $a1[VehicleColor]
<br>First Reg. Date: $a1[firstreg]
<br>Engine Power: $a1[cc]
<br>Chassis No: $a1[chassis]
<br>Engine No: $a1[engine]
<br>Transmission: $a1[trans]
<br>Drive Side : $a1[driveside]
<br></font></td>\n\t<td width=\"40%\" valign=top align=center><font size=2 face=verdana color=blue ><B>Price: $MyPrice</td>\n</tr>\n\n<tr>\n\t<td valign=top><br><b>Car ID: $a1[ListingID]</b><br><br>$desc<br>";
[code]

cameraman

7:05 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple things first - get that font tag out of there, you're making the CSS folk grit their teeth, and that's not good for their tooth enamel. When you refer to array elements you should use quotes if the index is non-numeric; for example, $a1[3] and $a1[7] are ok, but $a1[VehicleYear] should be $a1['VehicleYear'] unless you have declared VehicleYear a constant.

Up in the head of your html document (if there's other stuff in the head, you would of course leave it there, just adding the style section):
<head>
<style type="text/css">
<!--
.info { font-family: Arial, Helvetica, sans-serif; font-size:12pt; color:black; }
.bt { font-weight:bold; }
-->
</style>
</head>

Play with the 12pt adjusting the number until it looks the same size as you're getting from <font size=3>. Now, down in your table, add the 'class' defined above to each of the <td> that should have that font:
<td width=\"60%\" class=\"info\" valign=\"top\">

finally, use "span" along with the class "bt" above where you want bold text:
<br><span class=\"bt\">Year:</span> $a1['VehicleYear']
<br><span class=\"bt\">Mileage:</span> $a1['mileage'] miles
.
.
Also get into the habit of adding a trailing slash to <br> so it looks like: <br />
It looks dumb (to me) but you'll thank me one day.
You might want to read through the tutorials on CSS and HTML at w3schools.com.