I think I have my array correctly inputted but echoing it out to put it into a table is being difficult. I don't know where I am wrong.
Here is my code:
<?php
error_reporting(E_ALL);
//days - Sunday thru Saturday
$daysOfTheWeek = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
//sleep schedule
$sleepSchedule = array( 0 => 'go to sleep early', 1 => 'go to sleep on time', 2 => 'go to sleep on time', 3 => 'go to sleep on time',
4 => 'go to sleep on time', 5 => 'stay up late', 6 => 'stay up late');
//the chore list
$thingsToDo = array(
0 => array('Cleanup the house', 'Do dishes', 'Weekly Quiz!'), //row 1
1 => array('Grocery shop'), //row 2
2 => array('Walk at the park', 'Read the weekly PHP chapter', 'Take out the food!', 'Cook dinner!'), //row 3
3 => array('Homework due!', 'Ice cream sundae!'), //row 4
4 => array('Walk the dog'), //row 5
5 => array('Excercise', 'Vist Family'), //row 6
6 => array('Watch my favorite Tv show', 'Shopping!', 'Make take out food!', 'Relax!!') //row 7
);
echo '<tr>';
echo '<th>Days of the week</th>';
for ($i = 0; $i < sizeof($daysOfTheWeek); $i++) {
echo "<td>{$daysOfTheWeek[$i]}</td>";
}
echo '</tr>';
echo '<tr>';
echo '<th>Sleep Schedule</th>';
for ($i = 0; $i < sizeof($sleepSchedule); $i++) {
echo "<td>{$sleepSchedule[$i]}</td>";
}
$thingsToDo = array(
0 => array('Cleanup the house', 'Do dishes', 'Weekly Quiz!'), //row 1
1 => array('Grocery shop'), //row 2
2 => array('Walk at the park', 'Read the weekly PHP chapter', 'Take out the food!', 'Cook dinner!'), //row 3
3 => array('Homework due!', 'Ice cream sundae!'), //row 4
4 => array('Walk the dog'), //row 5
5 => array('Excercise', 'Vist Family'), //row 6
6 => array('Watch my favorite Tv show', 'Shopping!', 'Make take out food!', 'Relax!!') //row 7
);
I am good up until the bullet point for each day. Then I have my echo code:
echo '<th>ToDo list</th>';
$sizeOfThingsToDo = sizeof($thingsToDo);
for ($i = 0; $i < $sizeOfThingsToDo; $i++) {
$list = $thingsToDo[$i];
echo '<ul><td><li>';
echo $list[0].'<br>';
echo $list[1].'<br>';
echo $list[2].'<br>';
echo $list[3].'<br>'; echo '</ul></td></li>';
You're mixing table elements (
<th>
,<td>
) with list ones (<ul>
,<li>
). Here is how you can do what you want as a list :EDIT : the same as a row of your table
REEDIT : added bullet points.