/    Sign up×
Community /Pin to ProfileBookmark

Hi

I am new to php. I am trying to write a message board sort of website using javascript, where I will need to store each message with a rating, and maybe eventually replies/comments. I then need to access the data in order to reload the page.

I was thinking of writing a text file for each message. Then going through all the text files in the folder in order to retrieve all the messages. Is this the best way to do it?

Also, how do I integrate PHP code into my javascript? and if I save twice using the same filename, does it overwrite? and how can I look through a folder, and read all of the files?

Thanks for the help

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Dec 30.2010 — I think you want to pick up a book or read tutorials on php and mysql. Your best bet would be to store the data in a database. You would be using php and mysql to insert, update and select the data from the database. If you want to get fancy and not have a page refresh then you can use javascript and ajax to connect to a php file that will return the data you need.
Copy linkTweet thisAlerts:
@NihilisteDec 30.2010 — Like skywalker2208 said,

To do all the 'data handling' stuff, use a database, not a file.

And, if you want to integrate this with JavaScript, I'll suggest you to have a look at Ajax + Json tutorials/examples, you'll probably find some useful things ...
Copy linkTweet thisAlerts:
@eval_BadCode_Dec 31.2010 — I can actually see a LOT of benefits to using XML over SQL.

But how do YOU actually go about doing this? Learn some PHP, XML, XSLT.

I don't see how javascript helps anything.


Sounds crazy ? I hope you make it.
Copy linkTweet thisAlerts:
@eval_BadCode_Dec 31.2010 — Heh I thought about this... Well there's no reason you'd have to learn php to complete this forum idea. You could use a serverside include to a little bash and a javascript interpreter to process your xml (fancy flat file)... Then just drop the xml and an xsl into the picture and you wouldn't have to touch php or sql :p

I was thinking of writing a text file for each message. Then going through all the text files in the folder in order to retrieve all the messages. Is this the best way to do it?[/QUOTE]
best is relative... but in general you would have a hard time finding someone who thinks its best.

Also, how do I integrate PHP code into my javascript?[/QUOTE]

[code=php]
<?php echo "<html><head></head><body><script>alert('" . rand(0,9999) . "');</script></body></html>"; ?>
[/code]


and how can I look through a folder, and read all of the files?[/QUOTE]
[code=php]
<?php

if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handlen";
echo "Files:n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$filen";
}
}

?>
[/code]
×

Success!

Help @alfehaieotasdh 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.15,
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,
)...