Page 1 of 1

Formatting table having problems - can anyone help

Posted: Mon Dec 20, 2004 5:36 am
by mohson
Guys, I want to incorporate some formatting to my table to give each of the coloums a heading and format the table but when I add my coding ithe screen goes blank.

how would I go about incorporating the formatting below into my code which is below this.

Code: Select all

echo "<table width="50%" border="0" cellpadding="2" cellspacing="2">
    <tr>
        <td width="110"><b><small>ID</small></b></td>
        <td><b></b></td>
		<td><b><small>First Name</small></b></td>
		<td><b><small>Surname</small></b></td>
		<td><b><small>Organisation</small></b></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Notes</small></b></td>
		
    </tr>";

Code: Select all

"<table>";while ($row = mysql_fetch_object($sql)) 
 

{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor="$color"><td>".$count . '</td><td> ' . $row->person_id .'</td><td>'.        
	$row->salutation .'</td><td>'.         
	$row->firstname .'</td><td>'.         
	$row->surname .'</td><td>'.        
 	$row->organisation .'</td><td>'.        
	$row->role.'</td><td>'.       
 	$row->address1 .'</td><td>'.        
	$row->address2 .'</td><td>'.       
 	$row->city .'</td><td>'.       
 	$row->postcode .'</td><td>'.        
	$row->telephone .'</td><td>'.        
	$row->mobile .'</td><td>'.        
	$row->fax .'</td><td>'.        
	$row->dateoflastcontact.'</td><td>'.        
	$row->datecontactagain  .'</td><td>'.       
 	$row->email .'</td><td>'.    
	$row->notes .'</td></tr>';

$count += 1;
}

echo "</table>";

Posted: Mon Dec 20, 2004 11:41 am
by raging radish
You need to echo "<table>" at line 3.
What results are displayed as it is currently set up? Looks like it would output a single long row.

Posted: Mon Dec 20, 2004 4:17 pm
by mohson
I have already done that at line 1 everything works fine a the results are displayed correctly - I havent got an issue with the results its the table that I need to sort out - I need to add coloum headings to the tables where do I add the coloum headings -

Posted: Mon Dec 20, 2004 5:38 pm
by raging radish
Put the column headings before entering the while loop so they don't repeat with each iteration.

Sorta like:

Code: Select all

echo "<table><tr><td>heading1</td><td>heading2</td>etc...";
while ($row = mysql_fetch_object($sql)) {
//rest of code