|
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-03-2003 21:54
OK, I almost have my PHP blogger thingy done! ~whew!!~
The last thing is about to drive me nuts. I have all my blog entries saved in a sepearte folder. Each entry is saved as a Unix timestamp with a *.dat extension.
Now, What I would like to do is place each entry in a page with a radio button beside it. Then after all the entries are there (with the radio buttons), there will be buttons along the bottom for "Remove" and "Edit". For the remove, I am guessing from what I read the "unlink" function will work. But, what about editing the entry and then saving it?
I think my brain is about to fry!
Thanks in advance.
Later,
C:\
~Binary is best~
|
quisja
Paranoid (IV) Inmate
From: everywhere Insane since: Jun 2002
|
posted 06-03-2003 22:26
Load the entry as you would for displaying it normally, but instead contain its contents in a form, which you can them submit to edit the file server side.
|
Lurch
Paranoid (IV) Inmate
From: Behind the Wheel Insane since: Jan 2002
|
posted 06-04-2003 21:11
first, you'll have to open the file again with fopen()
then fwrite()
and don't forget to fclose()
here's a quick one that i whipped up for testing some stuff... its certainly not all that secure, (or clear) but it works for writing to the files.
code:
if (!$out_file){
echo("ERROR: There was no input file.");
exit;
}
$fe = fopen("$site_root/$filename", "w");
if (!$fe)
{
echo("The file could not be opened");
exit;
}
formatpage($out_file);
$out_file = stripslashes($out_file);
fwrite($fe, "$out_file");
fclose($fe);
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-06-2003 02:56
Forgive me if this doesn't make sense or whatnot. . . I have had very little sleep from a most "intoxicating" evening.
I think that after working on this part of it, is not so much how to edit or remove the posts. The probelm is with outputing each post with a radio button beside it that is linked to its file name.
So, if I have files: a.dat, b.dat, c.dat. And I want to output each one of them on the page along with a radio button that is linked to it, that is where I get lost. I know there must be a what that I could do a loop for each one of the files, and then output it along with adding a radio button.
I think I am confusing myself more and probably making this harder than what it really needs to be.
Any and all help would be greatful! ~Calling Suho to cell 922!~ Inmate in need of shock treatment!
Later,
C:\
~Binary is best~
|
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers
From: Germany Insane since: Sep 2001
|
posted 06-06-2003 08:39
a) file looping scripts in php - look around, there were a dozen in the last month of these babies.
b) you'd probably want to name your radiobuttons like name="mf[filename]"... then in php you can do a
foreach ($mf as $aFileToLoad)
{
//do whatever it takes to edit/delete the file.
}
|
Lurch
Paranoid (IV) Inmate
From: Behind the Wheel Insane since: Jan 2002
|
posted 06-06-2003 08:45
ok I had to read your posts a couple more times... i think i get it now... you want a checkbox beside each entry so you can check one and then at the bottom of the page choose whether you want to edit the selected entry, or delete it.. right? if you don't want to be able to select multiple entries (using a checkbox), then i'd use links instead of a form. put an "edit" and a "delete" link beside each entry..
or am i completely misunderstanding you?
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-06-2003 15:19
OK, thanks for the replys. Lurch you have a great idea there. Should have thought about that. Yes, adding a link beside each of the posts that says "Edit" and "Delete" seems to be the best way to go.
Now, I understand the process that I will have to go through to actually do the editing and delteting of the posts. The problem that I am having is to have the posts show up with the links for "Edit" and "Delete". This and having the links "linked" to each seperate post.
Lurch you have it. Now, if I could just get an idea of what it would take to loop through the posts and add the link and corresponding post.
Thanks for the help.
Later,
C:\
~Binary is best~
|
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers
From: Germany Insane since: Sep 2001
|
posted 06-06-2003 19:12
ok, while you're looping through the posts, and printing them any way,
place something like this wherever you want the links to be
(assuming the current Filename is in $aFilename)
print '<a href="'. $_SERVER['PHP_SELF']. '?edit='. base64encode($aFilename). '">Edit</a> - '
print '<a href="'. $_SERVER['PHP_SELF']. '?delete='. base64encode($aFilename). '" onClick="return confirm(\'Do you really want to delete this?\');">Delet</a>'.
ok, and somewher outside your loops, you have somthing like this...
if (isset($HTTP_POST_VARS['delete']))
{
$fileToEdit = base64decode($HTTP_POST_VARS['delete']);
if (file_exists($fileToEdit) && (dirname($fileToEdit) == './datastoragedir'))
{
unlink($fileToEdit);
}
}
and something alike for the editing part.
so long,
TP
PS: Am I mistaken, or is the signal/noise ration very much better around here in sscripting?
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-08-2003 06:03
OK, I think I am getting really confused. Look at this code. This is how I am saving the data to the flat files:
code:
//formating each posting. . .
fwrite($filePointer,"
<p class=\"date\">$myTime\r\n</p><br />
<div class=\"newsHeaders\">$header\r\n</div>
<p class=\"commentText\">$comment\r\n</p><br />
<hr />");
Now, if I were to open this file up and want to extract the data ($myTime, $header, and $comment), the data is actually what I typed. The problem that I am having is not understanding how to extract just that data, back into the appropriate text boxes. Eigh, I am royally confused.
Later,
C:\
~Binary is best~
|
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers
From: Germany Insane since: Sep 2001
|
posted 06-08-2003 10:27
ahh...
the better option would be to store the data in a more easily redable format and add the html when printing the stuff...
but I'll get you started on parsing your current files...
(it's a tad bit messy, having to rely on the previous findings for the offset, but should work well enough, provided you don't have any html tags in the data itself.
$rawdata = "
<p class=\"date\">$myTime\r\n</p><br />
<div class=\"newsHeaders\">$header\r\n</div>
<p class=\"commentText\">$comment\r\n</p><br />
<hr />";
$dateStart = strpos($rawdata,"<p class=\"date\">") + strlen("<p class=\"date\">");
$dateEnd = strpos($rawdata,'</p><br />',$dateStart);
$date = substr($rawdata,$dateStart,$dateEnd - $dateStart);
$headerStart = strpos($rawdata,"<div class=\"newsHeaders\">", $dateend) + strlen("<div class=\"newsHeaders\">");
$headerEnd = strpos($rawdata,'</div>',$headerStart);
$header = substr($rawdata, $headerStart, $headerEnd - $headerStart);
$dataStart= strpos($rawdata,"<p class=\"commentText\">", $headerEnd) + strlen("<p class=\"commentText\">");
$dataEnd = strpos($rawdata,'</p><br />',$dataStart);
$data = substr($rawdata, $dataStart, $dataEnd- $dataStart);
so long,
Tyberius Prime
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-08-2003 18:12
TP, you know, you're right. I think I need to go back and look at how I am saving the data. OK, thanks for the code, it won't go unused, but I am going back and saving the data in a different manner.
But, I am wondering if this would be a good way:
Save the file as a *.dat file with the name being the Unix timestamp. But, in the info itself, have it save the file to look like:
$myTime = (insert date here)
$header = (insert whatever I typed in the text box)
$comment = (again, insert whatever I typed)
OR
have it save it so that the different entries are saved seperated by colons. Such as:
June 8th, 2003 : My Header : My comments
OR
do you have a better solution. I don't think that going back and changing the code to save the info is going to be that much work, but
it will be a heck of a lot easier to extract the data.
Thanks for all your help guys, I am learning and without a teacher or someone else to talk to about this, this board is my only resource besides other website. So I appologize if I am beating a dead horse.
Later,
C:\
~Binary is best~
[This message has been edited by CPrompt (edited 06-08-2003).]
|
butcher
Paranoid (IV) Inmate
From: New Jersey, USA Insane since: Oct 2000
|
posted 06-08-2003 20:55
CPrompt
If you save the info your putting in your text files with a seperator between each field as your suggesting, you can use fgetcsv() to parse your file when you pull it back out for editing.
Then you can loop through the fields almost like a database result.
-Butcher-
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-09-2003 00:44
I'll give it a go. Thanks butcher.
Later,
C:\
~Binary is best~
|
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers
From: Germany Insane since: Sep 2001
|
posted 06-09-2003 13:57
the easiest thing is putting your data into an array
(like
$myData = array('timestamp' => $timestamp,'header' =>$header,'text' => $text);
)
and then using serialize() and unserialize to store and retrieve it...
writing would be
fwrite($fileHandle,serialize($myData));
and reading would be
$myData = unserialize(fread($fileHandle));
which then would be addressed via
print ($myData['timestamp']);
and so forth...
so long,
TP
Ps: Feel free to be come a member in the growing club of people that are using my icq as a php-help desk ;-)
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 06-09-2003 16:01
quote: Ps: Feel free to be come a member in the growing club of people that are using my icq as a php-help desk ;-)
An offer to teach someone should not go unnoticed ;-)
Be expecting a ICQ message from me later.
But, that does sound like a good and efficent way of doing it.
Later,
C:\
~Binary is best~
|