Jump to content

AidanPT

New Members
  • Posts

    6
  • Joined

  • Last visited

AidanPT's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey, I'm pretty new to this site so I thought I would try it out! You never know!... I am currently building a private messaging system on my website, it's a lot of code so I will try to cut it down, if you require anymore code to help me out, please let me know and I will post it. The problem I am having, in your "inbox" the messages you have sent or received are displayed with the title of (SUBJECT). When you click the subject, you can see all the messages you or the other user have sent to each other. With first and last names. The 2 codes below gather this information from the databases, which is absolutely fine. Although, instead of showing the (SUBJECT) on the inbox page, i would prefer to show the (FIRST NAME + LAST NAME) of who the message is to or from. Just like you can see in the actual message itself. I cannot figure out how to do this. The second code below does this for the view message page, although the top code gathers information for the inbox page, I have tried my best to combine the users info from the 2nd part to the 1st part, but all this does is show every message as the logged in users first and last names, not who the message is sent to or received from, is there a way to do this? Here are the 2 codes: <?php function fetch_conversation_summery(){ $sql = "SELECT `conversations`.`conversation_id`, `conversations`.`conversation_subject`, MAX(`conversations_messages`.`message_date`) AS `conversation_last_reply`, MAX(`conversations_messages`.`message_date`) > `conversations_members`.`conversation_last_view` AS `conversation_unread` FROM `conversations` LEFT JOIN `conversations_messages` ON `conversations`.`conversation_id` = `conversations_messages`.`conversation_id` INNER JOIN `conversations_members` ON `conversations`.`conversation_id` = `conversations_members`.`conversation_id` WHERE `conversations_members`.`userid` = {$_SESSION['userid']} AND `conversations_members`.`conversation_deleted` = 0 GROUP BY `conversations`.`conversation_id` ORDER BY `conversation_last_reply` DESC"; $result = mysql_query($sql); $conversations = array(); while (($row = mysql_fetch_assoc($result)) !== false){ $conversations[] = array( 'id' => $row['conversation_id'], 'subject' => $row['conversation_subject'], 'last_reply' => $row['conversation_last_reply'], 'name' => $row['first_name'], 'unread_messages' => ($row['conversation_unread'] == 1), ); } return $conversations; } function fetch_conversation_messages($conversation_id){ $conversation_id = (int)$conversation_id; $sql = "SELECT `conversations_messages`.`message_date`, `conversations_messages`.`message_date` > `conversations_members`.`conversation_last_view` AS `message_unread`, `conversations_messages`.`message_text`, `users`.`first_name`, `users`.`last_name` FROM `conversations_messages` INNER JOIN `users` ON `conversations_messages`.`userid` = `users`.`userid` INNER JOIN `conversations_members` ON `conversations_messages`.`conversation_id` = `conversations_members`.`conversation_id` WHERE `conversations_messages`.`conversation_id` = {$conversation_id} AND `conversations_members`.`userid` = {$_SESSION['userid']} ORDER BY `conversations_messages`.`message_date` DESC"; $result = mysql_query($sql); $messages = array(); while (($row = mysql_fetch_assoc($result)) !== false){ $messages[] = array( 'date' => $row['message_date'], 'unread' => $row['message_unread'], 'text' => $row['message_text'], 'first_name' => $row['first_name'], 'last_name' => $row['last_name'], ); } return $messages; } I need to be able to recall the information as "$coversation['first_name']; $conversation['last_name']" to show the names, although this information is only available on the messages page as "$messages['first_name'];. I am currently displaying the subject as "$conversation['subject'];". Trying to turn subject into the first and last names. Files have been attached for reference. Thanks pmsettings.php inbox.php viewmessage.php
  2. I tried changing it, but couldn't get nothing that worked. Have tried changing the code to this: <?php session_start(); Echo "<img src 'http://basecentre.co.uk/user_bc_74hw438eryer90reh0e9rh83232_members/upload/".$_SESSION['photo'] ."> <br>"; Echo "<b>Name:</b> ".$_SESSION['first_name'] . "<br> "; ?> the name comes up, but the picture doesn't work ? Any ideas?
  3. Sorry I don't get what you mean, could you elabourate please? Cheers, Aidan.
  4. Hi, I posted a question a few days ago asking about this topic but since then I have encounted a few errors and changed the code. I am creating a website with a database that lets the user sign up, change details, etc... I am currently having issues letting the user have a profile image. I sorted a form which can be used to upload an image to a file on the website and then send the image name to the database to be recalled later. Uploading is all fine, name works and everything, the problem is recalling it back doesn't seem to work. I have tried a lot of codes, with the code below, I am able to recall the users first name and see that, but the photo will not work? If anybody has any ideas, could you please help me out? I am pretty new to this code so would appriciate it if you explained and helped in simple terms. Thanks! <?php session_start(); Echo "<".$_SESSION['photo'] ."> <br>"; Echo "<b>Name:</b> ".$_SESSION['first_name'] . "<br> "; ?> This comes up like this: <> Name: Aidan Have tried this as well... <?php session_start(); Echo "<img src 'http://basecentre.co.uk/user_bc_74hw438eryer90reh0e9rh83232_members/upload/".$_SESSION['photo'] ."> <br>"; Echo "<b>Name:</b> ".$_SESSION['first_name'] . "<br> "; ?> which comes up like this: "broken photo icon" Name: Aidan The name seems to work fine, it's getting the image to come up correctly or at all?
  5. Thanks for the help, I've just tried the script like this: <?php // Connects to your Database mysql_connect ("host","user","password") or die ("Could not conenct"); mysql_select_db("dbname") or die ("could not connect to dadabase!"); //Retrieves data from MySQL $data = mysql_query("SELECT * FROM users WHERE userid = $logged_in_userid") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo "<img src=http://www.mysite/users/upload/".$info['photo'] ."> <br>"; Echo "<b>Name:</b> ".$info['name'] . "<br> "; } ?> And had a message : "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" Very new to MYSQL and PHP so not sure how to change where you mentioned "And if you're just getting a single record you don't need the WHILE(), just read the record returned (if found)" Sorry, not great being a noob!
  6. Need help badly! Setting up a new website with user logins. Pretty simple kind of stuff. Started working on letting the user upload a profile photo for their account, managed to get the user to be able to upload the photo in to a file on the site (upload/) and the image name entered in to their user details in SQL database. Worked fine. Only problem is when I try to recall the information, i've only been able to recall everybody's information and not just the logged in user. Here is the code I'm using. Bare in mind, I'm no pro with PHP and SQL so please help with as many details as possible. Thanks! ---------------------------------------------------------- <?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()) ; mysql_select_db("database name") or die(mysql_error()) ; //Retrieves data from MySQL $data = mysql_query("SELECT * FROM users") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo "<img src=http://www.mysite/users/upload/".$info['photo'] ."> <br>"; Echo "<b>Name:</b> ".$info['name'] . "<br> "; } ?> ---------------------------------- This seems to recall everyones info. I only want the display photo to be shown for the logged in user. I have tried a lot of changes and either the image doesn't show or nothing shows.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.