Jump to content

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.