Hi all,
To make comments appear on different pages of your website (without getting mixed up), you’ll need to add a new column to the database, something like ‘page_id’.After this you will need to assign each page a unique ID number by which you will distinguish it from the others (the best option is to use the same ID your CMS has assigned to the page).
When you insert a comment, you will have to add this ID as well. To show the comments for this particular page, just add a WHERE clause to the SELECT query in demo.php:
[php] $comments = array();
$result = mysql_query(“SELECT * FROM comments
WHERE page_id = “.$theIDofThePage.” ORDER BY id ASC”);[/php]
I created a database, now after days of searching and a lot of trouble i still not able to get it working…
So i will be glad to get some help.
Ok, i created a database…, it is working.
I put this in my webpage:
[php]<?php
// Error reporting:
error_reporting(E_ALL^E_NOTICE);
include “connect.php”; // conection details in here
include “comment.class.php”;
/*
/ Select all the comments and populate the $comments array with objects
*/
$comments = array();
$result = mysql_query(“SELECT * FROM comments
WHERE page_id = “.$theIDofThePage.” ORDER BY id ASC”);
while($row = mysql_fetch_assoc($result))
{
$comments[] = new Comment($row);
}
?> [/php]
I created the database like this:
[code]–
– Table structure for table comments
CREATE TABLE comments
(
id
int(10) unsigned NOT NULL auto_increment,
name
varchar(128) collate utf8_unicode_ci NOT NULL default ‘’,
url
varchar(255) collate utf8_unicode_ci NOT NULL default ‘’,
email
varchar(255) collate utf8_unicode_ci NOT NULL default ‘’,
page_id
varchar(50) collate utf8_unicode_ci NOT NULL default ‘’,
body
text collate utf8_unicode_ci NOT NULL,
dt
timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;[/code]
Now, my page_id is in the database, but where must i put the “.theIDofThePage.”?
Hope someone understand want i’m doing here…