Page 1 of 1

Adding column names when using database

Posted: Fri Apr 28, 2006 9:19 am
by Wardy7
I need what I can only think is a very simple thing doing.

I have a table of data with 6 columns in that displays all the data in 6 colums when I call it fromthe database.
What I want is to add code so I can list the title for each column at the top. I want to do this from within this code instead of doing it by hand.

Does this makes sence, if so can anyone point me in the right direction, ta :)

Code: Select all

***snip***

    if(mysql_num_rows($result) == 0){ 
        echo("No articles yet! Why not be the first to submit one?!"); 
    } 

    $bgcolor = "#FFFFFF"; //
    $bgcolor2 = "#FBBC00"; //
    $bgcolor3 = "#FFCC33"; //
    $bgcolor4 = "#FFDF80"; //
    $bgcolor5 = "#FFEEB9"; //
    $bgcolor6 = "#FFF7DD"; //
    $bgcolor7 = "#FFFBEC"; //
	$font =    "Verdana, Arial, Helvetica, sans-serif"; //
    $fontsize = "2"; //
    $tdwidth = "120"; //
    $tdwidth2 = "90"; //
    $tdwidth3 = "100"; //

    echo("<table>"); 
      
    while($row = mysql_fetch_array($result)){ 
        if ($bgcolor == "#FFFFFF"){ 
            $bgcolor = "#FFFFFF"; 
        }else{ 
            $bgcolor = "#FFFFFF"; 
     } 

    echo("<tr bgcolor=".$bgcolor.">\n<td>");
    echo("<td width=".$tdwidth." bgcolor=".$bgcolor2.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo($row["deal"]);
    echo("<td width=".$tdwidth2." bgcolor=".$bgcolor3.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo($row["speed"]);
    echo("<td width=".$tdwidth3." bgcolor=".$bgcolor4.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo('£' . $row["cost"] . '');
    echo("<td width=".$tdwidth3." bgcolor=".$bgcolor5.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo($row["age"]);
    echo("<td width=".$tdwidth3." bgcolor=".$bgcolor6.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo($row["length"]);
    echo("<td width=".$tdwidth3." bgcolor=".$bgcolor7.">");
    echo("<font face=".$font.">");
    echo("<font size=".$fontsize.">");
    echo($row["offer"]);
    } 

    echo("</table>");
?>
Cheers
Wardy

Posted: Fri Apr 28, 2006 9:27 am
by feyd
The information is available from the keys of the array returned from mysql_fetch_array().