-Karl- Posted August 17, 2010 Share Posted August 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/ Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Hopefully this will help: I'm just not sure which type of query would be best for this. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100129 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100444 Share on other sites More sharing options...
ober Posted August 17, 2010 Share Posted August 17, 2010 Your question doesn't make ANY sense. Try again. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100474 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Look at the images? Pretty much explains it, the top is the database, the second image is what I'm aiming to achieve. Simples. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100485 Share on other sites More sharing options...
mattal999 Posted August 17, 2010 Share Posted August 17, 2010 $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. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100486 Share on other sites More sharing options...
ober Posted August 17, 2010 Share Posted August 17, 2010 Am I the only one not seeing images? Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100488 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Maybe? http://i37.tinypic.com/2mhvh2r.png That image is in my second post. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100496 Share on other sites More sharing options...
ober Posted August 17, 2010 Share Posted August 17, 2010 When I click that link, I get this: An HTTP error occurred while getting: http://i37.tinypic.com/2mhvh2r.png Details: "connect timed out". Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100497 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Try this image please, I've reuploaded him. http://img517.imageshack.us/img517/4491/exampleqm.png Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100500 Share on other sites More sharing options...
MatthewJ Posted August 17, 2010 Share Posted August 17, 2010 Mattal answered you already... are you not willing to try and understand what he posted? Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100501 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 Mattal answered you already... are you not willing to try and understand what he posted? I'm working on it now, I'm just making sure the image works. Try not to jump the gun? Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100505 Share on other sites More sharing options...
MatthewJ Posted August 17, 2010 Share Posted August 17, 2010 Well, it was a half hour ago.. and you've posted three times since But you're right... I'm somehow "jumping the gun" Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100506 Share on other sites More sharing options...
-Karl- Posted August 17, 2010 Author Share Posted August 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100509 Share on other sites More sharing options...
-Karl- Posted August 18, 2010 Author Share Posted August 18, 2010 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/210915-php-and-mysql-table-population/#findComment-1100745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.