Hillary Posted April 17, 2008 Share Posted April 17, 2008 i have a .csv file and i need to put it into a table this is what it looks like now: <?php $data = array(); $data = file("phillsstat.csv"); $record=array(); $i=0; foreach($data as $line) { print $line . "<br />"; $feild= explode(",",$line); $record[$i] = $field; $i++; } ?> this is the display... the same as the .csv: Rollins,4,18,5 Howard,4,14,3 Burrell,4,13,5 Victorino,4,15,2 Utley,4,14,5 but i need them in PHP in a table... i can do it in HTML but im not allowed to for this assignment. Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/ Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 yet another person wanting us to do their homework. Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519663 Share on other sites More sharing options...
Hillary Posted April 17, 2008 Author Share Posted April 17, 2008 im not asking anyone to do my homework for me jon and believe me, there is far more to this assignment than just this table. so, how about showing a little maturity and actually act 27 (unless that is a lie) and not bitch people out who are looking for help and either A.) not reply, or B.) give assistance. Also, where do you get off saying "yet another person wanting us....... US? what do you mean by "us" you and the php community that you have been apart of for 1 day? lets be real here jon... anyone else want to tell me im trying to get other people to do my homework? this is a php HELP forum i am only looking for help... i only need someone to explain to me in simple terms how to create a table in PHP... if you do not care to help me then please do not respond. thank you in advance to those who are actually of assistance. also i may have more questions along the way and i will continue to post them here because who else am i going to go to? Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519695 Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 *I'll take the bait..* I've been a part of the PHP community for longer than a day. I've been a part of *THIS* community for a day. 2nd, if you are mad because nobody will help you cheat, great. I don't usually argue with people who are just angry that I won't help, but in this case, I figured that needed to be addressed. third, Yes, I'm 27, but that's not really the issue here, seeing how some of the greatest help on this site is 15 and under. Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519699 Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 and just to be nice (the whole turn the other cheek thing): to create a table, load your data into an array, and then do this: <?php print "<table> <tr><td>Table column 1 header</td><td>etc</td><td>etc</td></tr>"; foreach ($array_name as $value){ //echo table data out here, one column at a time. I'll let someone else explain how to handle table rows and cells. I'm not feeling 100% generous right now. } ?> Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519701 Share on other sites More sharing options...
craygo Posted April 17, 2008 Share Posted April 17, 2008 Well you would have to do 2 arrays. first one puts each line into and array, Which you have done already, and then a second which you just about got. so what you need to do is have a loop inside a loop. first loop starts your row, second loop echo's the columns <?php echo "<table width=500\n"; $data = array(); $data = file("phillsstat.csv"); $record=array(); $i=0; foreach($data as $line) { echo " <tr>\n"; $field= explode(",",$line); foreach($field as $value){ echo " <td>$value</td>\n"; } echo " </tr>\n"; } echo "</table>"; ?> Ray Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519706 Share on other sites More sharing options...
Barand Posted April 17, 2008 Share Posted April 17, 2008 or <?php $f = fopen('hillary.csv', 'r'); echo '<table border="1">'; while ($row = fgetcsv($f,80)) { echo '<tr><td>' . join ('</td><td>', $row) . '</td></tr>'; } echo '</table>'; fclose ($f); ?> Link to comment https://forums.phpfreaks.com/topic/101583-how-do-i-make-a-table/#findComment-519855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.