freebsdntu Posted December 12, 2007 Share Posted December 12, 2007 Hi, I am quite a newbie in php, I am trying to write a comments system in php, you know, like the add comment functionality in msn space. I have done with the forms, quite simple form with just nickname and comment, and I know how to get the form input from user in php. Now the problem is how do I display the newly posted message? Like the one in msn space? I guess to achieve that, I have to modify the page, I have thought of using dom approach, but what if the form page is a php page, not html page? Ad there is no dom -> loadPHPFile() function. I wish you guys can figure out what i am trying to explaining. All hints are greatly appreciated! Thank you very much! Quote Link to comment Share on other sites More sharing options...
everisk Posted December 12, 2007 Share Posted December 12, 2007 I think you could try using SQL statement to fetch the row in descending order (you should already store something like id). That should fetch the latest row. Something like select * from your_table order by field_name DESC Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 12, 2007 Author Share Posted December 12, 2007 thank you for your kind reply,but after fetching it, how do I display it? Ok, there is a document called comments.php, in which the form is included, there is also a document called addmessage.php, which does the logic, what I am thinking of is there is a header("Location:comments.php") statement at the end of addmessage.php, which means that user will be redirected back to the addmessage.php page, and the comment he has just posted would appear in the addmessage.php, very much like the behavior of my space add comment functionality, right? So my problem is how do I insert the message posted to addmessage.php document. Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 13, 2007 Author Share Posted December 13, 2007 Any hints? I am stuck at this problem Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 13, 2007 Share Posted December 13, 2007 well you need to try this yourself, dont expect us to do all the work, i myself was once a "noob" at PHP so I will get you started, first off you need to store all your comments in a MySQL database, then simply do this (modify script with your details!) <?php $host = 'localhost'; // MySQL Host $username = 'username'; // Username $password = 'password'; // Password $db = 'database'; // Database $conn = mysql_connect($host, $username, $password); mysql_select_db($db, $conn); // Edit the following line $query = mysql_query("SELECT * FROM your_table DESC"); while($row = mysql_fetch_array($query)){ echo ' Posted By: '.$row['nickname'].'<br> Comment:<br> '.$row['comment'].'<br>'."\n"; } mysql_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 13, 2007 Author Share Posted December 13, 2007 thank you for your help,northern rock. I know how to do the database stuff,for your code,when you echo the data from mysql,where would it go?I guess it would go to the addmessage.php,right?What I would like to achieve is to echo the data to message.php,the page where the add message form is in. Anyway,I would try it and see. Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted December 13, 2007 Share Posted December 13, 2007 thank you for your help,northern rock. I know how to do the database stuff,for your code,when you echo the data from mysql,where would it go?I guess it would go to the addmessage.php,right?What I would like to achieve is to echo the data to message.php,the page where the add message form is in. Anyway,I would try it and see. isnt northern rock a bank that went bust??? think his name is northern flame Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 13, 2007 Author Share Posted December 13, 2007 ah,sorry,I watch too much EPL,LOL Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 13, 2007 Author Share Posted December 13, 2007 Thank you very much for the hints,Northern Flame.I got it done! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.