hateyourtv
09-17-2005, 03:38 PM
I'm tyring to use a for loop to print an array into a two-column HTML table.
I can only use one for loop (no while loops) and one array.
I can't figure out a way to print it to the table correctly. It's supposed to have movie titles in the left column and movie times on the right.
<?php
$movies = array ("Movie Titles","Movie Times", "Charlie and the Chocolate Factory","1:30 | 4:00 | 7:00 | 10:00", "Cave","2:30 | 4:45 | 7:30 | 9:15", "Four Brothers","2:15 | 4:50 | 7:20 | 9:50", "Red Eye","2:45 | 5:00 | 7:05 | 9:30", "The Skeleton Key","2:30 | 5:00 | 7:25 | 9:55", "Junebug","2:30 | 5:05 | 7:45 | 10:20", "March of the Penguins","12:30 | 2:55 | 5:10 | 7:15", "Must Love Dogs","12:55 | 3:50 | 6:45 | 9:15", "Transporter 2","5:45 | 7:10 | 8:15 | 9:35", "Wedding Crashers","1:20 | 4:30 | 7:30 | 10:30");
echo "<table width=\"500\" border=\"1\" cellpadding=\"10\">";
for ($i=0; $i < count($movies); $i++)
{
echo "<tr>";
echo "<td>$movies[$i]</td>";
echo "<td>$movies[$i]</td>";
echo "</tr>";
}
echo "</table>";
?>
I have even tried using foreach() and making the movie titles the index, but then i can't figure out how to change the for loop to make it print correctly.
Help!
I can only use one for loop (no while loops) and one array.
I can't figure out a way to print it to the table correctly. It's supposed to have movie titles in the left column and movie times on the right.
<?php
$movies = array ("Movie Titles","Movie Times", "Charlie and the Chocolate Factory","1:30 | 4:00 | 7:00 | 10:00", "Cave","2:30 | 4:45 | 7:30 | 9:15", "Four Brothers","2:15 | 4:50 | 7:20 | 9:50", "Red Eye","2:45 | 5:00 | 7:05 | 9:30", "The Skeleton Key","2:30 | 5:00 | 7:25 | 9:55", "Junebug","2:30 | 5:05 | 7:45 | 10:20", "March of the Penguins","12:30 | 2:55 | 5:10 | 7:15", "Must Love Dogs","12:55 | 3:50 | 6:45 | 9:15", "Transporter 2","5:45 | 7:10 | 8:15 | 9:35", "Wedding Crashers","1:20 | 4:30 | 7:30 | 10:30");
echo "<table width=\"500\" border=\"1\" cellpadding=\"10\">";
for ($i=0; $i < count($movies); $i++)
{
echo "<tr>";
echo "<td>$movies[$i]</td>";
echo "<td>$movies[$i]</td>";
echo "</tr>";
}
echo "</table>";
?>
I have even tried using foreach() and making the movie titles the index, but then i can't figure out how to change the for loop to make it print correctly.
Help!