Jump to content

PHP Help - returning information


mrjiggyhill

Recommended Posts

Hello all,

 

Need a little help. I created a form. I have a php script that is taking the information from the form (user input) and placing it into a file.

I also created a link to display this information from the file....and i'm having trouble with the coding to take the information from the file and to display it (preferably in a table - but I haven't gotten that far).

 

<?php

$Directory = fopen("directory.txt", "r");

$records[] = fgets($Directory);

 

while (!feof($Directory)) {

 

$row = explode(",",$records);

 

foreach ($row as $field) {

echo "$field";

}

}

 

fclose($Directory);

?>

 

So i'm using the fopen to open the file then using the fgets to grab that information. Then doing a while loop (not end of file). Exploding the information in order to remove the commas - then trying to take the information from the array and displaying it record by record. Not sure where i'm going wrong.....

Link to comment
https://forums.phpfreaks.com/topic/161395-php-help-returning-information/
Share on other sites

Okey heres what you was doing wrong

<?php
$Directory = fopen("directory.txt", "r");
//$records[] = fgets($Directory); //this would read the line into an array
while (!feof($Directory)) {
$records = fgets($Directory); //read line
$row = explode(",",$records);
foreach ($row as $field) {
	echo "$field";
}
}
fclose($Directory);
?>

 

 

untested code (for table)

<?php
$Directory = fopen("directory.txt", "r");
//$records[] = fgets($Directory); //this would read the line into an array
echo "<table width=\"100%\" border=\"1\">";
while (!feof($Directory)) {
$records = fgets($Directory); //read line

#$row = explode(",",$records);
//fancy trick
/*i am replacing , with </td><td> and adding <td> at the start and </td> at the end*/
echo "<tr>";
echo "<td>".str_replace(",","</td><td>",$records)."</td>";
echo "</tr>";
}
echo "</table>";
fclose($Directory);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.