FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


.txt file to .php Lined to tables





DanielXP
How can i make each line of a .txt file go in to a table

this is the code i want it to go into:
Code:
<table border="1" width="447" id="table4"><tr><td align="center" width="422" bgcolor="#7C9CE2">LINE ( ) HERE</td><td align="center" width="74" bgcolor="#7C9CE2">Delete</td></table>
afracsass
use include.
Code:
 
<table>
<?php include 'file.txt'; ?>
</table>
yjwong
^^ In a table...

You could put this HTML first:
Code:

<table border="1" width="447" id="table4">


Then put these PHP lines:
Code:

$file_array   =   file("example.txt");

foreach($file_array as $lines) {
   echo "<tr>";
   echo "<td align=\"center\" width=\"422\" bgcolor=\"#7C9CE2\">$lines</td>";
   echo "<td align=\"center\" width=\"74\" bgcolor=\"#7C9CE2\">Delete</td>";
   echo "</tr>";
}


Lastly, close the table:
Code:

</table>
DanielXP
ok i have the code after a few changes
Code:
<?php

$file_array   =   file("link.txt");

   echo "<table border=\"1\" width=\"447\" id=\"table4\">";

foreach($file_array as $lines) {
   echo "<tr>";
   echo "<td align=\"center\" width=\"422\" bgcolor=\"#7C9CE2\">$lines</td>";
   echo "<td align=\"center\" width=\"74\" bgcolor=\"#7C9CE2\">Delete</td>";
   echo "</tr>";
}

   echo "</table>";

?>



Now how can i make the delete as a hyperlink to delete that line?
BlackSkad
Code:
<?php
$file_array = file("link.txt");

echo "<table border=\"1\" width=\"447\" id=\"table4\">";

$size = count($file_array);
for($i = 0; $i < $size; $i++) {
   echo "<tr>";
   echo "<td align=\"center\" width=\"422\" bgcolor=\"#7C9CE2\">" . $file_array[$i] . "</td>";
   echo "<td align=\"center\" width=\"74\" bgcolor=\"#7C9CE2\">";
   echo "<a href=\"linkadmin.php?action=delete&link=$i\">Delete</a></td>";
   echo "</tr>";
}

echo "</table>";
?>

LINKADMIN.PHP
<?php
if ($_GET['action'] == "delete") {
   if (!isset($_POST['link']) || $_POST['link'] == "")
       die ("No link provided");

   $file_array = file ("link.txt");
   $fp = fopen ("link.txt", "w") or die ("Could not open file!");
   $size = count($file_array);
   for ($i = 0; $i < $size; $i++) {
      if ($i != $_POST['link'])
          fwrite ($fp, $file_array[$i]);
   }
   fclose ($fp);
}
?>
DanielXP
It justs keeps saying No link provided
BlackSkad
You need to replace the $_POST['link'] everywhere in linkadmin with $_GET['link'] (seems like I was a little confused yesterday Smile ).
I start to wonder if you know anything about PHP. Do not take it as an insult, but it would be better to start of with something easy as a guestbook or something...
DanielXP
Thanks BlackSkad Very Happy

If u know any good sites for learning PHP not just giving you the code i would like to hear
DanielXP
Works great for my links, but when i change them bits from link.txt to members.txt for my members area and test it. a little thing went wrong. 130 members deleted Confused Sad Confused
Related topics
php admin and mysql admin console
I cant install php chat tables nor set up diffrent subdomain
Create a txt file
PHP: Writing to txt file
Creating a .txt file
Open, Write to and Close a txt file using php
does someone have a simple "save to txt file" scri
Displaying .txt file on web page
I can't open directly .txt file on my desktop
Saving a .txt file to a ftp using vb6. i need help please
VB 6.0 need help loading a .txt file into a text box
is it possible to get a html text box to load a .txt file?
Using php to change content of a .txt
asp.net email form
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.