grahamb314 Posted June 2, 2009 Share Posted June 2, 2009 Hi all, I have a PHP connection to a database which retreives data such as Name, Day, StartTime and EndTime, I want to display the data in a table like so: Monday Tuesday Wednesday.... first event first event second event second event third event third event At the moment I have all the data in one column: Events: one (Monday two (Monday) three (Monday) one (Tuesday) two (Tuesday) etc etc Is there a sample of how to do this somewhere? Thanks! Quote Link to comment Share on other sites More sharing options...
Vince889 Posted June 2, 2009 Share Posted June 2, 2009 That would be simple. Lets see the code. Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks! $result = mysql_query("select * from table ORDER BY Day,StartTime"); echo '<table border="0">'; while($r=mysql_fetch_array($result)){ $Show=$r["Show"]; $StartTime=$r["StartTime"]; $EndTime=$r["EndTime"]; $Day=$r["Day"]; $Day++; echo"<tr>"; echo "<td>$Show</td><td> $StartTime</td> <td> $EndTime</td><td> $Day</td>"; echo"</tr>"; } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 2, 2009 Share Posted June 2, 2009 Here is an example.. <?php echo "<table>"; $myquery=mysql_query("SELECT field1, field2 FROM mytable"); while ($row = mysql_fetch_array($myquery)) { echo "<tr><td>$row[field1]</td><td>$row[field2]</td></tr>"; } echo "</table>"; ?> That will print a table with a new row for each field1 and field2 Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted June 2, 2009 Author Share Posted June 2, 2009 Here is an example.. <?php echo "<table>"; $myquery=mysql_query("SELECT field1, field2 FROM mytable"); while ($row = mysql_fetch_array($myquery)) { echo "<tr><td>$row[field1]</td><td>$row[field2]</td></tr>"; } echo "</table>"; ?> That will print a table with a new row for each field1 and field2 Hi, actually what I am looking for is to only display the days on the top row and then each event under the appropriate heading. eg go shopping goes under Monday and order take-away would be under Friday's heading for example. Attached my plan Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted June 2, 2009 Author Share Posted June 2, 2009 Attached [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 2, 2009 Share Posted June 2, 2009 I see.. there are several ways you can do that actually.. You could use nested tables.. Essentially have 1 outside table, the first <td> would be Monday and you list each event under this in the while loop checking each time to see if the day has changed on your query results. If it changes then you create a new <td> therefore putting it in the next column. When it comes down to it you really need to just play with the code and use logic to figure out how its going to output. Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks, I'll give that a go tomorrow! Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted June 3, 2009 Author Share Posted June 3, 2009 I can't for the life of me, work this out. Any ideas? Quote Link to comment 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.