/    Sign up×
Community /Pin to ProfileBookmark

Possible to add a comments section to pages with PHP

I’m a reasonable experienced coder for general languages like C/C++, BUT still pretty new to PHP, and unfortunately pretty lacking in database work. (I’ve done a few pretty decent mail forms for my various sites, and thats about it). For my “next trick” I’d like to be able to add the equivalent of a moderated “comments” area to various articles I write on my pages. Bear in mind none of my sites or pages are anything more than simple HTML/CSS, and have no CMS infrastructure like wordpress. But as with mailforms, I learned a great deal looking at examples. Maybe some of you can point me to some generic examples for something like this? I’ve never used MySQL or any database for that matter on a direct coding level, so I’m tempted to cop out and just build a simple text based flat file organized like a table, but something tells me I’d be re-inventing a lot of wheels. Perhaps with some examples I could pull this off?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@phpmillionNov 29.2017 — I believe you can simply search for PHP/MySQL tutorials and start with the most basic examples. This way you will learn step-by-step how database works with PHP.
Copy linkTweet thisAlerts:
@PeterPan_321authorNov 29.2017 — I believe you can simply search for PHP/MySQL tutorials and start with the most basic examples. This way you will learn step-by-step how database works with PHP.[/QUOTE]Tha

Thanks. So what you're saying is it would be wise to use a database for a task like this, rather than "wing it" from scratch with a file and file structure of my own? Something like MySQL wouldn't be overkill for something like this?
Copy linkTweet thisAlerts:
@NogDogNov 30.2017 — Tha

Thanks. So what you're saying is it would be wise to use a database for a task like this, rather than "wing it" from scratch with a file and file structure of my own? Something like MySQL wouldn't be overkill for something like this?[/QUOTE]


You could use a file-based system, but it does not scale well. For a few pages with a few comments, no big deal. But as you start having to read and parse larger amounts of data from files, it tends to take longer in direct proportion to the amount of data (and at some point may leave a linear relationship and become exponential). Modern databases, on the other hand, are designed from the ground up to efficiently store, retrieve, sort, and parse data very efficiently; so using a DB-driven solution would scale much better.

Therefore, if you see this as never becoming a large site with 100s of pages and 1000s of comments...I suppose whatever works for you is fine. But if you expect (hope?) it will grow, or if you just want to leverage this as a learning experience, I'd go with a DB-driven approach, even if just using SQLite within PHP rather than MySQL or such. If you use the PDO DB extension in PHP, it will be pretty easy to switch later to MySQL (or PostgreSQL or whatever) later, should you decide that would be better for you.

On a related note, for the fun of it I created my current blog specifically to see how simple I could keep it, including no database. I've been contemplating whether or not I want to add a comments facility or not, and so far I've not decided if I really want it, and if I do, will it be DB-driven or not. See https://github.com/nogdog/cwrblog if you're interested. ?
Copy linkTweet thisAlerts:
@PeterPan_321authorNov 30.2017 — @NogDog

I wouldn't mind seeing your code! I suppose you used a flat file with defined field sizes or delimiters (like a comma separated scheme)? Sadly my last use of Github was so long ago, I've forgotten my login details and need to re-register. Any chance you could post the code in a ZIP file here on the Webdevelopers board?
Copy linkTweet thisAlerts:
@NogDogNov 30.2017 — Attempted to upload the zip I downloaded from GitHub...

[ATTACH]17597[/ATTACH]

:rolleyes:

[canned-message]attachments-removed-during-migration[/canned-message]
×

Success!

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