Page 1 of 1

check boxes to delete lines??

Posted: Mon Dec 15, 2003 3:25 pm
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/

Posted: Mon Dec 15, 2003 6:30 pm
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

Posted: Mon Dec 15, 2003 7:37 pm
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.

Posted: Fri Dec 19, 2003 4:51 pm
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/

Posted: Fri Dec 19, 2003 5:05 pm
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

Posted: Fri Dec 19, 2003 5:19 pm
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/