tags:

views:

31

answers:

1

Hello,

The code below returns the 10 most recent entries to a MySQL database. That's what I want, but I also want it to display the results in an HTML table. Right now, only the most recent result is in a table, a one-row table. The rest of the results are displayed in a jumble of text. How could I get all of the results in a 10-row table?

Thanks in advance,

John

$sqlStr = "SELECT loginid, title, url, displayurl
                FROM submission ORDER BY datesubmitted DESC LIMIT 10";
    $result = mysql_query($sqlStr);

    $arr = array(); 
    echo "<table class=\"samplesrec\">";
    while ($row = mysql_fetch_array($result)) { 
        echo '<tr>';
        echo '<td class="sitename2"><a href="http://www.'.$row["url"].'"&gt;'.$row["title"].'&lt;/a&gt;&lt;/td&gt;';
        echo '<td class="sitename2"><a href="http://www.'.$row["url"].'"&gt;'.$row["loginid"].'&lt;/a&gt;&lt;/td&gt;';
        echo '</tr>';

    echo "</table>";    
A: 

Move the } for the while to be above the echo "</table>"; line.

(Marking this as community wiki because mjv really should have just made his comment an answer. ;))

Amber
Thanks... stupid mistake on my part.
John
@Dav Thank you for the credit; you could/should have claimed the reps, however. I tend to use comments, at least initially, with these very localized questions. Maybe this comes from my ambivalence on these, where I'm both trying to help the OP, but also finding ways of improving SO by not "polluting" its content with these one-use type of questions/answers.
mjv