Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Plano, Texas
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Writing table Rows in SQP Script

    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>";
    }


    TIA JoeP

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Plano, Texas
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    JoeP

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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 >.<
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    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
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •