Hi there.
Been a while since I posted but I am completely stuck where to start with this.
What I'm trying to achieve is a message board (not like a forum more like the facebook wall). A user logs in and there is a text box. The user writes a message into the text box and clicks submit. After this that persons name appears in bold on the first line. In the lines underneath is the users message. I preferably want this in a bordered box, but not essential. Also all the other messages users posted appear underneath.
The username is already in a DB table (mysql) called users from when that person logged in.
I know I need to create another table for the messages with a text value for the column of message. How do I automatically get the users username into that table. The PHP should already know the username. Am I right?
How do I extract the name? and on the following lines, how do I extract the message?
I'm completely clueless to this. I know this involves alot of MySql But I've posted here because this also includes alot of PHP.
Any help would be hugely appreciated.
Similar to facebook wall - no idea
Moderator: General Moderators
Re: Similar to facebook wall - no idea
Well there are quite a lot of questions there. And a lot of different subtleties that could affect the whole design, for instance;
- will you be saving the messages indefinitely?
- will you be allowing messages to be written as response to already listed messages?
- etc etc...
Anyway the whole thing, in my opinion, should take the form of an unordered list (with nested lists) and you can style that with css.
Ok so to answer your questions...
Hope this helps.
- will you be saving the messages indefinitely?
- will you be allowing messages to be written as response to already listed messages?
- etc etc...
Anyway the whole thing, in my opinion, should take the form of an unordered list (with nested lists) and you can style that with css.
Ok so to answer your questions...
I'd use sessions, get the username (or users unique id) when the user logs in and store it in the session, then when you enter the message to the message table then u add the username too. Research mysql_query especially SELECT, UPDATE, INSERT.sloppyjoe wrote:How do I automatically get the users username into that table
I have no idea? lol What do you mean? PHP only knows what you tell it.sloppyjoe wrote:The PHP should already know the username. Am I right?
Research mysql_query especially SELECT.sloppyjoe wrote:How do I extract the name? and on the following lines, how do I extract the message?
Hope this helps.
Re: Similar to facebook wall - no idea
Thanks neilos.
Firstly to answer your questions, no. The messages will not be kept indefinitely. I will update the MySql frequently and remove old posts that I feel are outdated. (Unless there is a way to only keep 50 posts in the databse). Also Replies to a message aren't needed.
I've already got the session inserted now So the messageboard page declares "Welcome (username)"
Im familar with select such as SELECT * FROM.
However, where I am now confused is taking data from two different tables.
I want the newest post in the DB to be displayed. How can I let the PHP know which post needs to be shown next. Is this the best way to go around it? Is there an easier way?
Firstly to answer your questions, no. The messages will not be kept indefinitely. I will update the MySql frequently and remove old posts that I feel are outdated. (Unless there is a way to only keep 50 posts in the databse). Also Replies to a message aren't needed.
I've already got the session inserted now So the messageboard page declares "Welcome (username)"
Im familar with select such as SELECT * FROM.
However, where I am now confused is taking data from two different tables.
I want the newest post in the DB to be displayed. How can I let the PHP know which post needs to be shown next. Is this the best way to go around it? Is there an easier way?
Re: Similar to facebook wall - no idea
There are many ways. And lots of pros and cons for doing it in each way.sloppyjoe wrote:Unless there is a way to only keep 50 posts in the databse
If the table has a unique identifier that can be used to link between the two tables then you can look into using the join command
http://www.tizag.com/mysqlTutorial/mysqljoins.php
However I think that it is best done with just using one table (for getting the message and author), the messages table contains three columns: author, message and timestamp.
Order them by time and list each one using the author and message through the use of a while loop, to construct a list of items. The HTML would want to look like this;
Code: Select all
<li><h3>Username</h3>User's message. Blah blah blah!</li>
<li><h3>Username</h3>User's message. Blah blah blah!</li>
<li><h3>Username</h3>User's message. Blah blah blah!</li>You could even put the date and time that it was posted.
Also you could add a unique identifier for each message and also a column for parent allowing for nested lists that have the appearance of;
Code: Select all
<li><h3>Username</h3>User's message. Blah blah blah!
<li><h3>Username</h3>User's response. Blah blah blah!</li>
<li><h3>Username</h3>User's response. Blah blah blah!
<li><h3>Username</h3>User's response. Blah blah blah!</li>
</li>
</li>
<li><h3>Username</h3>User's message. Blah blah blah!</li>
<li><h3>Username</h3>User's message. Blah blah blah!</li>Re: Similar to facebook wall - no idea
Okay thankyou for your input
Ive been working on it and Ive come up with this.
which has 2 problems.
Problem 1 = The page isn't working at all as I expected
Problem 2 = The user ebters their name rather than taking it straight from the session
heres my code
Any ideas why it isnt working?
and how to add the logged in username?
Ive been working on it and Ive come up with this.
which has 2 problems.
Problem 1 = The page isn't working at all as I expected
Problem 2 = The user ebters their name rather than taking it straight from the session
heres my code
Code: Select all
<?php
;
session_start();
//this checks to see if the $_SESSION variable has been not set
//or if the $_SESSION variable has been not set to true
//and if one or the other is not set then the user gets
//sent to the login page
if (!isset($_SESSION['username'])) {
header('Location: http://kaaleigh.byethost15.com/login.php');
}
?>
[b]NOT IMPORTANT MISS THIS[/b]
<HTML>
<head><title>Message Board - Logged In</title>
<link rel='stylesheet' href='layout.css'>
</head>
<body bgcolor="#fd8ecf">
<center><img src="headerpage.jpg"></center>
<div class="navbar">
<div class="button"><a href="index.html">Home</a></div>
<div class="button"><a href="news.html">News</a></div>
<div class="button"><a href="gallery.html">Gallery</a></div>
<div class="button"><a href="videos.html">Videos</a></div>
<div class="button"><a href="contact.html">Contact</a></div>
<div class="button"><a href="links.html">Links</a></div>
<div class="button"><a href="msg.html">Message Kaaleigh</a></div>
</div>
<div class="frame">
<frameset cols="25%,75%" noresize="noresize">
[b]SESSION STARTS HERE[/b]
<?php
session_start();
$username = $_SESSION['username'];
$password = $_SESSION['password'];
if(isset($_SESSION['username']) && isset($_SESSION['password'])) {
echo " <b>Welcome ".$username." <br><br></b>";
}
else {
echo "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
}
?>
[b]EVERYTHING HAS WORKED SO FAR. HERE WE ENCOUNTER PROBLEMS FOR THE COMMENT BOARD[/b]
<?php
mysql_connect("*******", "*********", "*********");
mysql_select_db("*********");
?>
<form action="messageboard.php" method="POST">
Message:<br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="submit" value="Post Thread">
</form>
<?php
mysql_connect("************", "************", "*********");
mysql_select_db("**********");
$time = time();
mysql_query("INSERT INTO messages VALUES(NULL,'$_POST[message]','$_POST[author]','0','$time')");
echo "Message Posted.<br><a href='commentboard.php'>Return</a>";
<?php
// I am selecting everything from the messages section in the database and ordering them newest to oldest.
$sql = mysql_query("SELECT * FROM messages ORDER BY posted DESC");
// Now I am getting my results and making them an array
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r[posted]);
// End of Array
}
?>
</body>
</html>Any ideas why it isnt working?
and how to add the logged in username?