/    Sign up×
Community /Pin to ProfileBookmark

Still don’t get it… edit/delete row.

OK, I’m getting nowhere, so I’m starting from scratch.

[URL=http://siriustechnology.com/php/table/]HERE[/URL] is a brief description of what I need.

Below is a writetable.php script kindly provided by [b]pyro[/b] (and messed up by me ? ) that I use to post data into those rows. Posting is just perfect and works like a charm.

Please, tell me what to incorporate into that script so I can utilize [b]edit | delete[/b]?
I’ve been reading about delete function and found something to this extent (examples from the manual):

[code=php]<?php
// destroy a single variable
unset($foo);

// destroy a single element of an array
unset($bar[‘quux’]);

// destroy more than one variable
unset($foo1, $foo2, $foo3);
?>
[/code]

I find it difficult to understand (I’m a visual person). Can someone show me something [b]working[/b] so I can disect (best way of learning for me) the script? Besides, I need it to enhance the actual project. too…

here is the original script [b]writetable.php[/b] – revised:

[code=php]

<?PHP

$filename = “table_text.htm”; #CHMOD to 0666

if (isset($_POST[‘submit’])) {
$contents = file($filename);

$file = “”;
foreach ($contents as $line) {
$file .= $line;
}

preg_match(“/(<table(.*?)> )/is”, $file, $matches);

$tableheader = $matches[0];
list($start, $end) = preg_split(“/<table(.*?)>/i”, $file);
$start .= $tableheader;

$new = ‘<tr>
<td>’.$_POST[‘column_one’].'</td>
<td>’.$_POST[‘column_two’].'</td>
<td><a href=rams/’.$_POST[‘column_three’].’>’.$_POST[‘column_four’].'</a></td>
<td>’.$_POST[‘column_five’].'</td>
</tr>
‘;

$data = $start.$new.$end;

$fp = fopen($filename, “w”);
flock($fp, LOCK_EX);
fwrite($fp, $data);
flock($fp, LOCK_UN);
fclose($fp);

header(“Location:../table_text.htm”);
}

?>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>Administration Options</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<link rel=”stylesheet” href=”../style.css” type=”text/css”>

</head>

<body bgcolor=”#F8F8F8″>
<form action=”<?PHP echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<table width=”186″>
<tr>
<td>Date:</td>
<td>
<input type=”text” name=”column_one”>
</td>
</tr>
<tr>
<td>Author:</td>
<td>
<input type=”text” name=”column_two”>
</td>
</tr>
<tr>
<td>Audio:</td>
<td>
<input type=”text” name=”column_three”>
</td>
</tr>
<tr>
<td>Name:</td>
<td>
<input type=”text” name=”column_four”>
</td>
</tr>
<tr>
<td>Time:</td>
<td>
<input type=”text” name=”column_five”>
</td>
</tr>
</table>
<input type=”submit” name=”submit” value=”Submit New Row” class=”subm”>
<div align=”center”> </div>
</form>
</body>
</html>

[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@SamFeb 09.2004 — here's some pseudo code, hope it helps

basically, we'll start out assuming you've mapped your big string that contains html into an array starting after <table> and ending before </table> with each element starting with <tr> and ending with </tr>

from here, we'll assume the user clicked the 3rd row (#2 in your array)

at this point, you can use
[code=php]
unset($arrayName[2]);
[/code]


then in your writing loop, it would write nothing for $arrayName[2], thus erasing it entirely from your record
Copy linkTweet thisAlerts:
@DariaauthorFeb 10.2004 — Thanks for advice, unfortunately, I can't use it - I don't have enough of initial understanding to follow through with what you suggest.

Could someone, PLEASE, PLEASE, PLEASE, show me the WORKING MODEL?
Copy linkTweet thisAlerts:
@pyroFeb 10.2004 — Using a database is probably the best way to go from here. Flatfiles are generally much harder to work with than databases, for data handling. I would recommend following that path.
Copy linkTweet thisAlerts:
@DariaauthorFeb 10.2004 — I'm looking into it, but I don't know where to start. My hosting company has a database manager, where I can define everything through "wizard", but for this I need a script with configuration, where I just plug in the database name, localhost, password, etc... I really don't want to start learning MySQL part right now - believe me, when I say I don't have time for this... Can there be a script where I start with a blank database and the script will plug all the values in?
Copy linkTweet thisAlerts:
@pyroFeb 10.2004 — [URL=http://www.phpmyadmin.net/]phpMyAdmin[/URL]
Copy linkTweet thisAlerts:
@DariaauthorFeb 10.2004 — Isn't it a bit bulky for just that one little script?
Copy linkTweet thisAlerts:
@pyroFeb 10.2004 — I use it for all my database management, as it makes things much easier. It'll make setting everything up much easier.
Copy linkTweet thisAlerts:
@DariaauthorFeb 10.2004 — Allright... I trust you ? I'll look into it.
Copy linkTweet thisAlerts:
@SamFeb 10.2004 — assuming you don't host it yourself, there's good adds your server already has phpmyadmin installed somewhere, all three of my servers use it.
×

Success!

Help @Daria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...