refiking Posted April 12, 2009 Share Posted April 12, 2009 Hi guys. I have no clue how to go about doing this. I can remove the header row, but I only want to pull one row - row 4. Here's what I currently have: $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { IF ($data[1] != "Description"){ Echo '<tr bgcolor="#99CC99" width="475" height="80" align="left"> <td width = "475" align="center" > ' . $data[0] . '<br />' . $data[1] . '<br /><a href="' . $data[3] . '" target="_blank">' . $data[2] . '</a><br /> </td> </tr>'; } fclose($handle); Link to comment https://forums.phpfreaks.com/topic/153733-solved-read-one-row-of-csv-file/ Share on other sites More sharing options...
refiking Posted April 12, 2009 Author Share Posted April 12, 2009 I just tried to add a loop snippet and ran into this error: fgetcsv(): 2 is not a valid stream on line 5 Here is the code: $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $i=0; if ($i = 3) { Echo '<tr bgcolor="' . $bgcolor . '" width="475" height="80" align="left"> <td width = "475" align="center" > ' . $data[0] . '<br />' . $data[1] . '<br /><a href="' . $data[3] . '" target="_blank">' . $data[2] . '</a><br /> </td> </tr>'; $i++; } fclose($handle); } Link to comment https://forums.phpfreaks.com/topic/153733-solved-read-one-row-of-csv-file/#findComment-807899 Share on other sites More sharing options...
refiking Posted April 12, 2009 Author Share Posted April 12, 2009 Now, I don't get any errors, but I am getting every record in the csv file again. Here's what I have right now: $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $i++; if ($i = $adnumber) { Echo '<tr bgcolor="' . $bgcolor . '" width="475" height="80" align="left"> <td width = "475" align="center" > ' . $data[0] . '<br />' . $data[1] . '<br /><a href="' . $data[3] . '" target="_blank">' . $data[2] . '</a><br /> </td> </tr>'; } } fclose($handle); Someone please help... ??? Link to comment https://forums.phpfreaks.com/topic/153733-solved-read-one-row-of-csv-file/#findComment-807908 Share on other sites More sharing options...
Axeia Posted April 12, 2009 Share Posted April 12, 2009 <?php $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $i++; if ($i == $adnumber) { echo '<tr bgcolor="' . $bgcolor . '" width="475" height="80" align="left"> <td width = "475" align="center" > ' . $data[0] . '<br />' . $data[1] . '<br /><a href="' . $data[3] . '" target="_blank">' . $data[2] . '</a><br /> </td> </tr>'; } } fclose($handle); ?> Proper indenting helps readability. I assume you've set $adnumber to 4 somewhere else? You've set $i to 0 before the loop? And you need to compare using == not =, = just assigned the value over and over. I've fixed it in the above code.. along with the indenting. Link to comment https://forums.phpfreaks.com/topic/153733-solved-read-one-row-of-csv-file/#findComment-807919 Share on other sites More sharing options...
Axeia Posted April 12, 2009 Share Posted April 12, 2009 Normally I just ignore PM's, but here you go: Hey Axeia, I really appreciate the help you gave me on that csv record issue. Is there a way to count the number of rows in a given csv file? Thanks! At the end of the ride $i would have the number of rows Link to comment https://forums.phpfreaks.com/topic/153733-solved-read-one-row-of-csv-file/#findComment-808113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.