Reading data from a MySQL database into a HTML Table?
So i am working on a project and need some advice.
I have a MySQL database that stores events, i know how to code this functionality in PHP but im just stuck of a few specifics.
As the project that I am creating is a timetable, the most important attributes are the day of the event, starting time and finishing time.
Once i have read this data from the MYSQL databa开发者_JAVA技巧se using my PHP script, how do i go about inserting these events in to a html timetable?
Lets say i have record like below in my events table:
Event ID = 01
Event Day = Monday Event Start = 12:00 Event End = 14:00How would I then put that into a html table, bearing in mind that i may have mutiple events for a day?
You can mix your result from PHP into HTML code:
<table>
<?php
foreach ($results as result){
echo '<tr><td>'.$result->field.'</td></tr>';
}
?>
</table>
Are you having trouble determining how the PHP mixes with the HTML in this situation? If so:
<table>
<thead>
<tr>
<th>Event ID</th>
<th>Event Day</th>
<!-- etc... -->
</tr>
</thead>
<tbody>
<?php while ($row = mysql_fetch_assoc($resultSet)) { ?>
<tr>
<td><!-- Event ID row data --></td>
<td><!-- Event Day row data --></td>
<!-- etc... -->
</tr>
<? } ?>
</tbody>
</table>
mysql_fetch_array($result) iterates the rows from your result. Just do something like this:
while ($row = mysql_fetch_array($result)) {
echo $row['fieldname'];
}
The above code would display every item in the result's column named "fieldname". Use HTML to format the results however you like.
u can do something like this http://monket.net/wiki-v2/Image:MonketCalendarLarge.png
<table>
<?php while ($row = mysql_fetch_assoc($result)) {?>
<tr>
<td>
Event ID = <?php $row['id'] ?> <br />
Event Day = <?php $row['day]?> <br/>
Event Start = <?php $row['start_date']?> <br/>
Event End = <?php $row['end_date']?>
</td>
</tr>
<?php } ?>
精彩评论