Google Answers Logo
View Question
 
Q: Text area PHP ( No Answer,   4 Comments )
Question  
Subject: Text area PHP
Category: Computers > Programming
Asked by: sjw-ga
List Price: $10.00
Posted: 26 Apr 2006 08:28 PDT
Expires: 26 May 2006 08:28 PDT
Question ID: 722986
I need to add a comment field that appends to the line being removed
in the code below, can someone help me out

<html>
<head>
<title>Postings</title>

<title>Testing - Not For Use Yet</title>
</head>
<body bgcolor="#0000FF">
<script language="JavaScript" src=checkall.js></script>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td><a href='pending.php'><font color="#000000"><b>Pending
Posts</font></a></td>
    <td><center><b><h1><a href='index.php'><font
color="#000000">Current Posts</font></a></td>
    <td><div align="right"><a href='resolved.php'><font
color="#000000">Past Posts</font></a></div></td>

  </tr>
<table border="1" width="100%" >
<tr>
<td>
<?php
$path_to_dir = 'post'; // path to text file
$file_contents = file("$path_to_dir/posts.txt"); // the file
$file_contents_deleted = file("$path_to_dir/past-posts.txt"); // the file
// [ DELETE ROUTINE ]
if($_POST['action'] == "delete"){ // delete triggered
$arrToDelete = $_POST['todelete']; // assign checked items array to var
if($arrToDelete != "") { // if the array isnt open proceed
foreach($arrToDelete as $key => $value) { // assign a key and value to
each checked item
$file_contents_deleted[] = $file_contents[$key];
array_splice($file_contents, $key, 1, ""); // assign null value to
each checked item in file_contents array
print("<font color=#00FF40>Removed <b> $value </b>Posts From Pending
List</font><br>");
}
$sizeof = count($file_contents_deleted); // count updated file_contents array
if($filehandle = fopen("$path_to_dir/past-posts.txt", "w")){ // open
the file for writing
for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
if($file_contents_deleted){
fputs($filehandle, $file_contents_deleted[$y]); // write the new
file_contents array to the file
}
}
fclose($filehandle); // close the file
}
$sizeof = count($file_contents); // count updated file_contents array
if($filehandle = fopen("$path_to_dir/posts.txt", "w")){ // open the
file for writing
for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
if($file_contents){
fputs($filehandle, $file_contents[$y]); // write the new file_contents
array to the file
}
}
fclose($filehandle); // close the file
}
}
}
?>
<?php     // [ READ & OUTPUT FILE CONTENTS ]     ?>
<!-- The Form & Table -->
<form name=binform method="POST" action="<?php $PHP_SELF ?>" style="margin:0;">
<input type="hidden" name="action" value="delete">
<table border="1" width="100%" bgcolor="#000000">
<tr>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=bin"><font color=000000>User</a></td>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=bintype"><font color=000000>Name</a></td>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=user"><font color=000000>Email</a></td>
<td class="spectable" bgcolor=#FFFF00><b><h2><center>Posts To Remove</td>
</tr>
<?php
$file_contents = file("$path_to_dir/posts.txt"); // the file
foreach($file_contents as $key=> $value){ // assign a key to each line in the file
if($file_contents[$key] != ""){
$entry = explode("\t", $file_contents[$key]); // break out each
delimeter - tab in this case
$entries[]=array('user'=>$entry[0], 'name'=>$entry[1],
'email'=>$entry[2],'key'=>$key, 'value'=>$value);
}
}
if ($entries) {
foreach ($entries as $key => $row) {
$bin[$key]  = $row['user'];
$bintype[$key] = $row['name'];
$user[$key] = $row['email'];
}
switch ($sort) {
case "user": array_multisort($user, SORT_ASC, $entries); break;
case "name": array_multisort($name, SORT_ASC, $entries); break;
case "email": array_multisort($email, SORT_ASC, $entries); break;
}
}
for($i=0; $i<sizeof($entries); $i++) {
print("<tr>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['user']."</td>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['name']."</td>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['email']."</td>
<td class=spectable bgcolor=FFFF00><h4><center><input type=checkbox
name=todelete[".$entries[$i]['key']."]
value=".$entries[$i]['value']."></center></td>
</tr>");
}
?>
<tr>
<td colspan="3" align="center" class="spectable"
bgcolor=FFFF00><h4><center><input type="submit" value="Remove Post(s)
From List"></td>
<td align="center" class="spectable" bgcolor=FFFF00><b>Check All
<input onclick="check_all_ch_1();" name="all_ch_1" type=checkbox>
?</td>
</tr>
</table>
</form>
</td>
</table>
<br><br><br>
 
The text field needs to be before the check box and would be for
comments. The user would need to be able to enter this themselves and
a single entry for each box check (marked to be removed from the first
file and moved the the "deleted" file). But also be able to enter
entries for multiple records at once. The comments should be appended
to the line when being "moved" to the "deleted" file. Right now, you
can checked multiple boxes and all the "checked" records are moved to
the "deleted" file, I do not want to lose that function or the ability
to check all the records at once to be removed. The end result should
be a new column that is a text area that appends to the file once
checked for removal.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Text area PHP
From: thegreatall-ga on 11 May 2006 16:51 PDT
 
So, you want a textbox to add comments next to each item that will be
in the list? and you want to beable to store each item that has been
commented?

I am a little bit hazy on what exactly you want, please elaborate a little more.
Subject: Re: Text area PHP
From: sjw-ga on 19 May 2006 09:09 PDT
 
You are correct, that is exactly what I need. To be able to store the
comment for each item that has been commented.
Subject: Re: Text area PHP
From: thegreatall-ga on 19 May 2006 18:53 PDT
 
Ok, I used some of the already modified code and made some "home
brewed code" and this is what I came up with:

<html>
<head>
<title>Postings</title>

<title>Testing - Not For Use Yet</title>
</head>
<body bgcolor="#0000FF">
<script language="JavaScript" src=checkall.js></script>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td><a href='pending.php'><font color="#000000"><b>Pending
Posts</font></a></td>
    <td><center><b><h1><a href='index.php'><font
color="#000000">Current Posts</font></a></td>
    <td><div align="right"><a href='resolved.php'><font
color="#000000">Past Posts</font></a></div></td>

  </tr>
<table border="1" width="100%" >
<tr>
<td>
<?php
$path_to_dir = 'post'; // path to text file
$file_contents = file("$path_to_dir/posts.txt"); // the file
$file_contents_deleted = file("$path_to_dir/past-posts.txt"); // the file
// [ DELETE ROUTINE ]
	if($_POST['action'] == "delete"){ // delete triggered
		$arrToDelete = $_POST['todelete']; // assign checked items array to var
		if($arrToDelete != "") { // if the array isnt open proceed
			foreach($arrToDelete as $key => $value) { // assign a key and value
to each checked item
				$file_contents_deleted[] = $file_contents[$key];
				array_splice($file_contents, $key, 1, ""); // assign null value to
each checked item in file_contents array
				print("<font color=#00FF40>Removed <b> $value </b>Posts From
Pending List</font><br>");
			}
			$sizeof = count($file_contents_deleted); // count updated file_contents array
			if($filehandle = fopen("$path_to_dir/past-posts.txt", "w")){ //
open the file for writing
				for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
					if($file_contents_deleted){
						fputs($filehandle, $file_contents_deleted[$y]); // write the new
file_contents array to the file
					}
				}
				fclose($filehandle); // close the file
			}
			$sizeof = count($file_contents); // count updated file_contents array
			if($filehandle = fopen("$path_to_dir/posts.txt", "w")){ // open the
file for writing
				for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
					if($file_contents){
						fputs($filehandle, $file_contents[$y]); // write the new
file_contents array to the file
					}
				}
				fclose($filehandle); // close the file
			}
		}
	}elseif($_POST['save']){
		foreach($file_contents as $key => $value){ // assign a key to each
line in the file
			if($file_contents[$key] != ""){
				$entry = explode("\t", $file_contents[$key]); // break out each
delimeter - tab in this case
				$entries[]=array('user'=>$entry[0], 'name'=>$entry[1],
				'email'=>$entry[2],'key'=>$key, 'value'=>$value, 'comment'=>@$entry[3]);
			}
		}
		foreach($_POST['comments'] as $key => $value){
			$entries[$key]['comment'] = $value;
		}
		foreach($entries as $key => $value){
			foreach($value as $key1 => $value1){
				@$output .= "$value\t";
			}
			@$output .= "\n";
		}
		if($filehandle = fopen("$path_to_dir/posts.txt", "w")){ // open the
file for writing
			fputs($filehandle, @$output); // write the new file_contents array to the file
			fclose($filehandle); // close the file
		}
	}
?>
<?php     // [ READ & OUTPUT FILE CONTENTS ]     ?>
<!-- The Form & Table -->
<form name=binform method="POST" action="<?php $PHP_SELF ?>" style="margin:0;">
<input type="hidden" name="action" value="delete">
<table border="1" width="100%" bgcolor="#000000">
<tr>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=bin"><font color=000000>User</a></td>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=bintype"><font color=000000>Name</a></td>
<td class="spectable" bgcolor=#FFFF00><center><b><h2><a href="<?php
$PHP_SELF ?>?sort=user"><font color=000000>Email</a></td>
<td class="spectable" bgcolor=#FFFF00><b><h2><center>Posts To Remove</td>
            <td class="spectable" bgcolor=#FFFF00><center>Comments</td>
</tr>
<?php
$file_contents = file("$path_to_dir/posts.txt"); // the file
	foreach($file_contents as $key=> $value){ // assign a key to each line in the file
		if($file_contents[$key] != ""){
			$entry = explode("\t", $file_contents[$key]); // break out each
delimeter - tab in this case
			$entries[]=array('user'=>$entry[0], 'name'=>$entry[1],
			'email'=>$entry[2],'key'=>$key, 'value'=>$value, 'comment'=>@$entry[3]);
		}
	}
	if ($entries) {
		foreach ($entries as $key => $row) {
			$bin[$key]  = $row['user'];
			$bintype[$key] = $row['name'];
			$user[$key] = $row['email'];
		}
		switch ($sort) {
			case "user": array_multisort($user, SORT_ASC, $entries); break;
			case "name": array_multisort($name, SORT_ASC, $entries); break;
			case "email": array_multisort($email, SORT_ASC, $entries); break;
		}
	}
	for($i=0; $i<sizeof($entries); $i++) {
		print("<tr>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['user']."</td>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['name']."</td>
<td class=spectable bgcolor=FFFF00><h4><center>".$entries[$i]['email']."</td>
<td class=spectable bgcolor=FFFF00><h4><center><input type=checkbox
name=todelete[".$entries[$i]['key']."]
value=".$entries[$i]['value']."></center></td>
<td class=spectable bgcolor=FFFF00><h4><center><input type=textbox
name=comment[".$i."]
value=\"".@$entries[$i]['comment']."\"></center></td></tr>"
);
	}
?>
<tr>
<td colspan="3" align="center" class="spectable"
bgcolor=FFFF00><h4><center><input type="submit" value="Remove Post(s)
From List"></td>
<td align="center" class="spectable" bgcolor=FFFF00><b>Check All
<input onclick="check_all_ch_1();" name="all_ch_1" type=checkbox>
?</td>
            <td class="spectable" bgcolor=#FFFF00><center><input
type="submit" name="save" value="Save" /></center></td>
</tr>
</table>
</form>
</td>
</table>
<br><br><br>



I did not test this only because I dont have the proper files and info
to test it. If you would like however I would consider working with
you to get it to work correctly.

You may reach me though email at: thegreatall[at]gmail.com

Hope that works,
-ALL (thegreatall)
Subject: Re: Text area PHP
From: sjw-ga on 23 May 2006 09:20 PDT
 
The format is correct, now I need to be able to pass the information
into the text file from the comment field text box.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy