check boxes to delete lines??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

check boxes to delete lines??

Post by wesnoel »

I'm sure this has been touched on before, I just can't find anything.

Basic stuff I guess, I know how to write and read text files but what I want to do is take my text file and list each line in a form with a checkbox next to it.

If you click on a check box and hit submit or in this case delete it would then delete that line.

It is a text file of email address and names each on different lines.

name,email
name,email
name,email

and so on


I know how to do most of this just not the checkboxes and delete of a line.

Could anyone help?

TIA

Wes/
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i'm not sure that you can do this, i ran into this problem a long time ago and then decided to never use a flat file ever again, SQL ONLY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!, but good luck at any rate
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Look into [php_man]file[/php_man]. Try loading a file with that, and walk the array it returns, printing each line with a checkbox. then to delete the lines, use file() again, and unset() the unwanted lines. You can use [php_man]implode[/php_man] to put the array back to a big string to write out.
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Post by wesnoel »

OK this is what I came up with for displaying the text inside a form with radio buttons. This works like a charm.

Code: Select all

<?php
$email == array();
$initials == array();

// Get a file into an array.  In this example we'll go through HTTP to get 
// the HTML source of a URL.
$email_list= "fake_email_lists.txt";
$lines = file ($email_list);

echo $email_list;

//echo "<br><table width="70%" border="0" cellspacing="0" cellpadding="1">";
//echo "<form name ="email" action ="delete_email.php">";





// Loop through our array, show html source as html source; and line numbers too.
foreach ($lines as $line_num => $line) {

   $split = explode( ",", $line);

	    		$initials = $split[0];
			$email = $split[1];
			
 
 $initials = strtoupper($initials);
 $email = strtoupper($email);





   
//WRITE THE NOTE LISTING
echo "<tr><td width="35"><font size="3" face="Arial" color="#DC143C">$line_num</td><td width="80"><font size="3" face="Arial" color="#003366"><b>$initials</b></td><td width="230"><font size="2" face="Arial" color="#003366">$email</td><td><input type="radio" name="line" value="$line_num" border="0"><br></td></tr>";

   
   
}



?>
once the radio button is checked and the form is submitted. I want it to display what info is being deleted before it gets deleted.

Right now it will display the correct line number but as for the email and initials, only the last line displays. How can I display the correct information from the line I want to delete.


This is what I submit the form to for testing the output:

Code: Select all

<?php

$line = $_POST['line'];
$email = $_POST['email'];
$initials = $_POST['initials'];

echo $line;
echo "<br>";
echo $initials;
echo "<br>";
echo $email;


?>
Anyone know how to get the right info from each line?


Wes/
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I'm not totally sure what you mean but my guess is that you have some checkboxes and when you click more then one it only shows the last result.

Read this tutorial for some help using checkboxes:
http://codewalkers.com/tutorials/12/4.html
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Post by wesnoel »

Actually everything is working fine from the check box, It is only passing the line number.

The problem I'm having now is when I want to display the email and initials, it is displaying the last last line of the text file, because it was the last thing added to the email and initials arrays.

My question is how do I pass the correct email and initials to the next page.

I hope that is a little clearer.


Wes/
Post Reply