View Full Version : Writing table Rows in SQP Script

01-19-2008, 01:24 AM
Below is a piece of a script I have that reads a database and writes a table and presents the data in a 3 column table with one record per row. The variable $bdnum_rows gives me the number of records that I present in that table when the script runs.

My Table Layout is Name (With a hyperlinklink) || Birth Year || Death Date

I have no trouble with Table Header Rows and closing the table.

Would someone assist and advise me how I can change my echo statement to write a table row with the same data, but the table would be 9 columns with 3 records per row.

$bdnum_rows = mysql_num_rows($query2); // This gives me the number of records that meet my criteria. It varies each time the script is called. Usually in range of 1-50.

The sample script:

while ($row = mysql_fetch_array($query2) ) {
$deathdate = $row["deathdate"];
if ($deathdate == "Y"){$deathdate = "Unknown";}

echo "<tr><td align= 'left' valign='top'><font face='Arial' size='1'><a href=\"getperson.php?personID=" . $row["personID"] . "&tree=" . $row["gedcom"] . "\">" . $row["firstname"] . " " . $row["lastname"] . "</a><i></td><td align='left'><font face='Arial' size='1'>&nbsp;" . $row["BirthYear"] . "<td align= 'left' valign='top'><font face='Arial' size='1'>&nbsp;d. " . $deathdate . "</i></font></td></tr>";


01-19-2008, 11:47 PM
You mean to sort of flip the view, instead of each record on a line with the corresponding fields in the columns, that the records are in the columns and the corresponding fields in the rows?
That is far less pleasant to do, essentially you will need to retrieve the data required and place them into individual arrays (or a very clever ally associative array), and iterate from that point.
I will suggest instead that you develop this in a more xhtml strict fashion. Should you place your data in div/span combinations correctly, you can use CSS to change the layout instead of relying on the tables to do the same.

Oh, one other option I can think of, in each of your columns you could embed another table, that way you can have multiple row/columns per given column.

Hope that helps!

01-20-2008, 12:36 AM
Thank You!

I actually used this to get it to work:

while ($row = mysql_fetch_array($query2)) {
$deathdate = $row["deathdate"];
if ($deathdate == "Y"){$deathdate = "Unknown";}
if ($hopColumn == 4) {$hopColumn = 1;}
if ($hopColumn == 1) {echo "<tr>";}
echo "<td align='left'><font face='Arial' size='1'>&nbsp;&nbsp;<a href=\"getperson.php?personID=" . $row["personID"] . "&tree=" . $row["gedcom"] . "\">" . $row["firstname"] . " " . $row["lastname"] . "</a><i></td><td align='left'><font face='Arial' size='1'>&nbsp;&nbsp;" . $row["BirthYear"] . "<td align= 'left' valign='top'><font face='Arial' size='1'>&nbsp;&nbsp;d. " . $deathdate . "</i></font></td>";
if ($hopColumn == 3) {echo "</tr>";}
$hopColumn = $hopColumn +1;

Then I changed the format to one column after all!

Thanks for your reply, though.


01-20-2008, 08:08 PM
NP mate, glad it helped you out!
These kinds of topics I have trouble answering simply because of my 'div'ing nature. I've not used a table in years now so it makes it tricky to try and explain >.<

01-20-2008, 09:31 PM
But for that kind of output the semantic method would be to use a table because you are actually displaying tubular data... creating it with CSS is more hassle and certainly not semantic by todays standards

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum