Jump to content

PHP and MySQL table population


-Karl-

Recommended Posts

I have a table created containing the following.

 

name url members date

 

I want to populate a table like so:

 

Dates name1 name2 name3

date  membersforname1 membersforname2 membersforname3

anotherdate  membersforname1 membersforname2 membersforname3

 

So I need the dates to form each of the rows, but also, have the members in the correct places for the names.

 

Not sure if any of that made sense, if you want me to go in to more detail just ask.

Link to comment
Share on other sites

$prevdate = NULL;
$query = mysql_query("SELECT * FROM tablename ORDER BY date ASC");
echo "<table><tr>";
while($row = mysql_fetch_array($query)) {
    if($row['date'] == $prevdate) {
        echo "<td>BLAH BLAH BLAH</td>";
    } else {
        echo "</tr><tr>";
        echo "<td>BLAH BLAH BLAH</td>";
    }
    $prevdate = $row['date'];
}
echo "</tr></table>";

 

It won't work as you expect, but you should be able to see my logic.

Link to comment
Share on other sites

Anyway, I've had a little mess around

 

$prevdate = NULL;
$query = mysql_query("SELECT * FROM tracked ORDER BY date ASC");
$query2 = mysql_query("SELECT * FROM tracked GROUP BY name ASC");
echo "<table><tr>";
echo '<tr>
            <td>Date</td>';
while($row2 = mysql_fetch_assoc($query2)) {
            echo '<td>'.$row2['name'].'</td>';
}
echo '</tr>';
while($row = mysql_fetch_assoc($query)) {
    if($row['date'] == $prevdate) {
        echo '<td>'.$row['members'].'</td>';
    } else {
        echo "</tr><tr>";
        echo '<td>'.$row['date'].'</td>';
    }
    $prevdate = $row['date'];
}
echo "</tr></table>"; 

 

It's got the correct layout now, however, no members appear for name2, when there are numbers in the database. Can't figure out why.

 

EDIT: Actually, the members that come under name1, are actually the members for name2.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.