Page 1 of 1

formatting my output - having problems

Posted: Thu Dec 16, 2004 7:28 am
by mohson
The code below makes my records appear in plain text and all joined up together..

How would I incoporate my previous alternate color scheme and table layout - shown below after my current echo statement - Ive tried so many ways but it just wont work - would you know how to do it or does anyone have their own way of presenting results in an alternating colors table - please take a look at my original code and tell me how I could incorporate it.. thanks

CURRENT echo statement is like this:

Code: Select all

while ($row = mysql_fetch_object($sql)) {
echo $count . '. ' . $row->person_id .''. 
		$row->salutation .''. 
		$row->firstname .''. 
		$row->surname .''. 
		$row->organisation .''.
		$row->role.''.
		$row->address1 .''.
		$row->address2 .''.
		$row->city .''.
		$row->postcode .''.
		$row->telephone .''.
		$row->mobile .''.
		$row->fax .''.
		$row->dateoflastcontact.''.
		$row->datecontactagain  .''.
		$row->email .''.

		$row->notes .''.'<br />' . "\r\n"; // this is example, you may enter here anything you like
$count += 1;
}
Before it used to be like this and all the results would appear in table format with alternating colors. How would I incorporate this into my code above??

Code: Select all

// Begin your table outside of the array
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>"; 
	
// Define your colors for the alternating rows

$color1 = "#ADD8E6";
$color2 = "#E0FFFF";
$row_count = 0; 
	
/* Performing SQL query */



$query = "SELECT * FROM people ORDER BY firstname LIMIT  0, 10"; 
$result = mysql_query($query) or die("Query failed : " . mysql_error());



/* Printing results in HTML */

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$person_id = $line["person_id"];
    $salutation = $line["salutation"];
	$firstname = $line["firstname"];
    $surname = $line["surname"]; 
	$organisation = $line["organisation"];
	$role = $line["role"];
	$address1 = $line["address1"];
	$address2 = $line["address2"];
	$city = $line["city"];
	$postcode = $line["postcode"];
	$telephone = $line["telephone"];
	$mobile = $line["mobile"];
	$fax = $line["fax"];
	$dateoflastcontact = $line["dateoflastcontact"];
	$datecontactagain = $line["datecontactagain"];
	$notes = $line["notes"];
	$email = $line["email"];
	
	
	/* Now we do this small line which is basically going to tell
    PHP to alternate the colors between the two colors we defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2; 
	
	
	 // Echo your table row and table data that you want to be looped over and over here. 
  
echo "<tr>
    <td width="20" bgcolor="$row_color" 	 nowrap><a href ="Upeople.html">$person_id 
    </td>
    <td bgcolor="$row_color">$salutation </td>
	<td width="110" bgcolor="$row_color" nowrap><a href="mailto: $email">$firstname 
    </td>
	<td width="100" bgcolor="$row_color" nowrap><a href="mailto: $email">$surname 
    </td>
	<td width="100" bgcolor="$row_color" nowrap>$organisation 
    </td>
	<td bgcolor="$row_color">$role</td>
	<td width="100" bgcolor="$row_color" nowrap>$address1
    </td>
	<td width="100" bgcolor="$row_color" nowrap>$address2
    </td>
	<td bgcolor="$row_color">$city</td>
	<td width="110" bgcolor="$row_color" nowrap>$postcode
    </td>
	<td bgcolor="$row_color">$telephone</td>
	<td bgcolor="$row_color">$mobile</td>
	<td bgcolor="$row_color">$fax</td>
	<td width="100" bgcolor="$row_color" nowrap>$dateoflastcontact
    </td>
	<td width="100" bgcolor="$row_color" nowrap>$datecontactagain
    </td>
	<td width="300" bgcolor="$row_color" nowrap>$notes 
    </td>
	
	
	
	</tr>"; 
	
	    // Add 1 to the row count

    $row_count++;
}

Posted: Thu Dec 16, 2004 8:18 am
by harsha

Code: Select all

<?php
$Count = 1;
while ($row = mysql_fetch_object($sql))
	{
		/* if count even print td  with bgcolor Red*/
		if($count%2 == 0 )
			{
				echo "<td bgcolor="#FF0000">".$row['attribute']."<td>"
			}
		else 
			{
				echo "<td bgcolor="#CCCCCC">".$row['attribute']."<td>"		
			}
		$count++;
	}
?>
sorry I haven;t fine tuned it but I feel this is the logic

Posted: Thu Dec 16, 2004 8:23 am
by lostboy
try something like

Code: Select all

// Define your colors for the alternating rows

$color1 = "#ADD8E6";
$color2 = "#E0FFFF";
$color = $color2;

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

($color==$color2)? $color = $color1 : $color = $color2;
echo '<tr backgroundcolor="$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>'; // this is example, you may enter here anything you like
$count += 1;
}

Posted: Thu Dec 16, 2004 9:07 am
by mohson
thank you - the formatting works but the colors dont appear?? any ideas

Posted: Thu Dec 16, 2004 12:31 pm
by lostboy
sorry, that should be bgcolor not backgroundcolor