Hillary Posted March 22, 2008 Share Posted March 22, 2008 Another assignment: i don't know how to make the table portion but all 35 of the cards show up in order like they are supposed to. i just need to figure out how to make 5 rows and 7 columns... Create a program that uses five for-loops. Each for loop creates a row within a table. When the program is done, a table with five rows of seven columns should be produced, like a calendar. The first thirty-five cards should be displayed in order, one per cell. That is, the first row should start with the ace of clubs. The second row should start with the eight of clubs. The third row with the two of diamonds, and so on. To make things easy, create an array of filenames of the cards, like we did in class. <html> <head> <title></title> </head> <body> <?php $deck = array( "ac.gif", "2c.gif", "3c.gif", "4c.gif", "5c.gif", "6c.gif", "7c.gif", "8c.gif", "9c.gif", "tc.gif", "jc.gif", "qc.gif", "kc.gif", "ah.gif", "2h.gif", "3h.gif", "4h.gif", "5h.gif", "6h.gif", "7h.gif", "8h.gif", "9h.gif", "th.gif", "jh.gif", "qh.gif", "kh.gif", "as.gif", "2s.gif", "3s.gif", "4s.gif", "5s.gif", "6s.gif", "7s.gif", "8s.gif", "9s.gif", "ts.gif", "js.gif", "qs.gif", "ks.gif", "ad.gif", "2d.gif", "3d.gif", "4d.gif", "5d.gif", "6d.gif", "7d.gif", "8d.gif", "9d.gif", "td.gif", "jd.gif", "qd.gif", "kd.gif", ); for ( $a =0; $a <=7; $a++ ) { echo "</td><img src=\"../cards/" . $deck[$a] . "\"/><td>"; } for ( $b =8; $b <=14; $b++ ) { echo "</td><img src=\"../cards/" . $deck[$b] . "\"/><td>"; } for ( $c =15; $c <=21; $c++ ) { echo "</td><img src=\"../cards/" . $deck[$c] . "\"/><td>"; } for ( $d =22; $d <=29; $d++ ) { echo "</td><img src=\"../cards/" . $deck[$d] . "\"/><td>"; } for ( $e =30; $e <=34; $e++ ) { echo "</td><img src=\"../cards/" . $deck[$e] . "\"/><td>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/97323-for-loop/ Share on other sites More sharing options...
dbillings Posted March 22, 2008 Share Posted March 22, 2008 <html> <head> <title></title> </head> <body> <?php $deck = array( "ac.gif", "2c.gif", "3c.gif", "4c.gif", "5c.gif", "6c.gif", "7c.gif", "8c.gif", "9c.gif", "tc.gif", "jc.gif", "qc.gif", "kc.gif", "ah.gif", "2h.gif", "3h.gif", "4h.gif", "5h.gif", "6h.gif", "7h.gif", "8h.gif", "9h.gif", "th.gif", "jh.gif", "qh.gif", "kh.gif", "as.gif", "2s.gif", "3s.gif", "4s.gif", "5s.gif", "6s.gif", "7s.gif", "8s.gif", "9s.gif", "ts.gif", "js.gif", "qs.gif", "ks.gif", "ad.gif", "2d.gif", "3d.gif", "4d.gif", "5d.gif", "6d.gif", "7d.gif", "8d.gif", "9d.gif", "td.gif", "jd.gif", "qd.gif", "kd.gif", ); echo "<table> <tr>"; for ( $a =0; $a <=7; $a++ ) { echo "</td><img src=\"../cards/" . $deck[$a] . "\"/><td>"; } echo "</tr> <tr>"; for ( $b =8; $b <=14; $b++ ) { echo "</td><img src=\"../cards/" . $deck[$b] . "\"/><td>"; } echo "</tr> <tr>"; for ( $c =15; $c <=21; $c++ ) { echo "</td><img src=\"../cards/" . $deck[$c] . "\"/><td>"; } echo "</tr> <tr>"; for ( $d =22; $d <=29; $d++ ) { echo "</td><img src=\"../cards/" . $deck[$d] . "\"/><td>"; } echo "</tr> <tr>"; for ( $e =30; $e <=34; $e++ ) { echo "</td><img src=\"../cards/" . $deck[$e] . "\"/><td>"; } echo "</tr> </table>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/97323-for-loop/#findComment-498030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.