|
|
|
| У меян есть удаление строки скрипт
<?
$file_name = "../base/guest_bd.php";
$array = file($file_name);
foreach
($array as $key => $str)
{
$array[$key] = trim ($str);
}
if
(!isset ($_POST['string']))
{
echo "<form method=post action=?delete_g=1>";
echo "<input type=text name=string>";
echo "<input type=submit value=удалить>";
echo "</form>";
echo "Всего записей $total_guest";}
else
{
unset ($array[$_POST['string'] - 1]);
$fp = fopen ($file_name, "w");
fwrite ($fp, implode ("\n", $array)."\n");
fclose ($fp);
}
?>
|
и скрипт редактирование записей!
Позже дам!
Немогли бы помочь соеденить их! как нить! ну что бы кочрое вот скрипт редактирвоания там бьяснить легче будет
<?
$puti="../base/guest_bd.php";
// Обработчик HTML-формы
if(!empty($_POST))
{
// Читаем содержимое файла
$arr = file("$puti");
$i = 0;
foreach($arr as $line)
{
if(!empty($line))
{
list($msg, $name, $mail, $data, $ip) = explode("||", $line);
$user['msg'][] = $msg;
$user['name'][] = $name;
$user['mail'][] = $mail;
$user['data'][] = $data;
$user['ip'][] = $ip;
}
}
// Изменяем выбраннные элементы массива
$user['msg'][$_POST['index']] = $_POST['msg'];
$user['name'][$_POST['index']] = $_POST['name'];
$user['mail'][$_POST['index']] = $_POST['mail'];
$user['data'][$_POST['index']] = $_POST['data'];
$user['ip'][$_POST['index']] = $_POST['ip'];
// Записываем изменённое содержимое обратно в файл
$content = "";
for($i = 0; $i < count($user['name']); $i++)
{
$content .= $user['msg'][$i]."||".$user['name'][$i]."||".$user['mail'][$i]."||".$user['data'][$i]."||".$user['ip'][$i]."||\r\n";
}
$fd = fopen("$puti","w");
if(!$fd) exit("Невозможно открыть файл");
fwrite($fd,$content);
fclose($fd);
}
// Выводим HTML-формы для редактирования
$arr = file("$puti");
$i = 0;
foreach($arr as $line)
{
if(!empty($line))
{
list($msg, $name, $mail, $data, $ip) = explode("||", $line);
$user['msg'][] = $msg;
$user['name'][] = $name;
$user['mail'][] = $mail;
$user['data'][] = $data;
$user['ip'][] = $ip;
}
}
for($i=count($arr)-1; $i>=0; $i--)
{
echo "<form method=post action=?redaktor_g=1>
<table width='460' id='table1' cellspacing='0' cellpadding='0' style='border-style: solid; border-width: 0; ' height=145>
<tr>
<td colspan=2>
<input type='text' name='name' size='16' value='".$user['name'][$i]."'><input type='text' name='data' size='18' value='".$user['data'][$i]."'><input type='text' name='mail' size='13' value='".$user['mail'][$i]."'><input type='text' name='ip' size='15' value='".$user['ip'][$i]."'>
<textarea rows=8 name=msg cols=71>".$user['msg'][$i]."</textarea></td>
</tr>
<tr>
<td colspan='2' height=28>
<input type=hidden name=index value=$i>
<input type='submit' name='Submit0' value='Save'>
</td>
</tr>
</table>
</form>";
}
?>
|
Помогите к редактированию удаления добавить! ну например рядом с кнопкой сохранить была кнопка удалить и эта запись удалялась ваще :(
всю ночь пытался :( | |
|
|
|
|
|
|
|
для: Panker
(15.04.2006 в 09:18)
| | К кнопке
<input type='submit' name='Submit0' value='Save'>
добавьте
<input type='submit' name='delete' value='Delete this row'>
Обработчик:
<?
if(isset($_POST['delete'])){
$file=file($puti);
$count=count($file);
$fp=fopen($puti,'w+');
for($i=0;$i<$count;$i++){
if($i==$_POST['index']){continue;}
fwrite($fp,$file[$i]."\r\n");
}
fclose($fp);
}//isset post delete
?>
|
| |
|
|
|
|
|
|
|
для: Shorr Kan
(15.04.2006 в 09:27)
| | я обработчик в туже страницу сунул и при заходе на страницу у меян добавляется 3 пустых сообщения :( | |
|
|
|