Click to See Complete Forum and Search --> : Create a One Column Table


Dysan
11-09-2007, 07:10 PM
Hi,

Using the following code, how do I create a one column table, with "Firstname, Lastname & Sex" as the heading.

Also, how do I display the row data (i.e Firstname etc) using the following format?:

$record) $Firstname
$Lastname ($Sex)

<link rel="stylesheet" type="text/css" href="Index.css" />

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die(mysql_error());
}

mysql_select_db("WB", $con);

$result = mysql_query("SELECT * FROM Birds");

//This should be the column heading.
echo "Firstname, Lastname & Sex";

$record = 1;
while($row = mysql_fetch_array($result))
{
//Display all this on each row.
echo $record++;
echo $row['Firstname'];
echo $row['Lastname'];
echo $row['Sex'];
}

mysql_close($con);
?>

bokeh
11-10-2007, 05:30 AM
Personally I'd use a list (because the data is a list, ie not tabular):$result = mysql_query("SELECT * FROM Birds");

echo "<h1>Firstname, Lastname & Sex</h1>\n<ol>\n";

while($row = mysql_fetch_array($result))
{
echo "<li>{$row['Firstname']}, {$row['Lastname']}, {$row['Sex']}</li>\n";
}

echo "</ol>\n";

malarz
11-10-2007, 08:54 AM
Or you can put it into a table:

echo "<table>\n<tr><th>Firstname</th><th>Lastname</th><thSex</th></tr>\n";
$result = mysql_query("SELECT * FROM Birds");
while ($row=mysql_fetch_array($result))
{
echo "<tr><td>" . $row['Firstname'] . "</td><td>" . $row['Lastname'] . "</td><td>" . $wor['Sex'] . "</td></tr>\n";
}
echo "</table>\n";