Jump to content

problems displaying data from tables


kirkh34

Recommended Posts

im trying to display messages that have been put in the trash by users, sent and received... the message info comes from the message_rec and message_sent tables. the member info comes from a mymembers table....the message info displays but the the picture of the person it was sent to or received from along with the name is not displaying... also the the link does not have the correct id... i seem to have a problem with the query to the mymembers table.. it is displaying the ID of the first person in the row for all messages it seems, i've tried to look for something simple but i've been looking at it for so long, all of it is kind of not making any sense

<?php
$sql3 = mysql_query("SELECT * FROM message_rec WHERE to_user ='$id' AND message_trash = '1' UNION SELECT * FROM message_sent WHERE from_user ='$id' AND message_trash = '1' ORDER BY message_date DESC")
or die (mysql_error()); 



while ($row = mysql_fetch_array($sql3))
{

		$message_id = $row["message_id"];
		$message_content = $row["message_content"];
		$message_date = $row["message_date"];
		$message_title = $row["message_title"];
		$to_user = $row["to_user"];  // the id of the session user in the message_rec table OR the id of the receiver in the message_sent table
		$from_user =$row["from_user"];  // the id of the receiver in the message_rec table OR the id of the sender (session user) in the message_sent table
		$message_read = $row["message_read"];



if 	($to_user != $id)  /// if the message was a sent message
				/// i want the $id to be = to the person it was sent to (so the pic display below will have the correct id)
	{

		$id = $row["to_user"];


	} //close if



	$sql4 = mysql_query("SELECT * FROM mymembers WHERE id='$id'")  
		or die (mysql_error()); 

		while ($row = mysql_fetch_array($sql4))
		{

		$firstname = $row["firstname"];
		$lastname = $row["lastname"];
		}





$position= 30; // Define how many character you want to display. 
$title = substr($message_title, 0, $position); 

$content = substr($message_content, 0, $position);

/// pic display

    $check_pic = "memberFiles/$id/image01.jpg";
$default_pic = "memberFiles/0/image01.jpg";
if (file_exists($check_pic)) {
    $pic_id = "<img src=\"$check_pic\" width=\"50px\" />"; // forces picture to be 100px wide and no more
} else {
$pic_id = "<img src=\"$default_pic\" width=\"50px\" />"; // forces default picture to be 100px wide and no more
}

 

Link to comment
https://forums.phpfreaks.com/topic/201088-problems-displaying-data-from-tables/
Share on other sites

here's the full php section

<?php
$sql3 = mysql_query("SELECT * FROM message_rec WHERE to_user ='$id' AND message_trash = '1' UNION SELECT * FROM message_sent WHERE from_user ='$id' AND message_trash = '1' ORDER BY message_date DESC")
or die (mysql_error()); 



while ($row = mysql_fetch_array($sql3))
{

		$message_id = $row["message_id"];
		$message_content = $row["message_content"];
		$message_date = $row["message_date"];
		$message_title = $row["message_title"];
		$to_user = $row["to_user"];  // the id of the session user in the message_rec table OR the id of the receiver in the message_sent table
		$from_user =$row["from_user"];  // the id of the receiver in the message_rec table OR the id of the sender (session user) in the message_sent table
		$message_read = $row["message_read"];



if 	($to_user != $id)  /// if the message was a sent message
				/// i want the $id to be = to the person it was sent to (so the pic display below will have the correct id)
	{

		$id = $row["to_user"];


	} //close if



	$sql4 = mysql_query("SELECT * FROM mymembers WHERE id='$id'")  
		or die (mysql_error()); 

		while ($row = mysql_fetch_array($sql4))
	{


		$firstname = $row["firstname"];
		$lastname = $row["lastname"];

	}




$position= 30; // Define how many character you want to display. 
$title = substr($message_title, 0, $position); 

$content = substr($message_content, 0, $position);

/// pic display

    $check_pic = "memberFiles/$id/image01.jpg";
$default_pic = "memberFiles/0/image01.jpg";
if (file_exists($check_pic)) {
    $pic_id = "<img src=\"$check_pic\" width=\"50px\" />"; // forces picture to be 100px wide and no more
} else {
$pic_id = "<img src=\"$default_pic\" width=\"50px\" />"; // forces default picture to be 100px wide and no more
}

$envelope_read = "images/read.gif";
$envelope_unread = "images/unread.gif";
if ($message_read == '0'){
	$envelope = "<p style=color:#000;>Unread</p>";
} else {
	$envelope = "<p style=color:#9f9f9f;>Read</p>";
}


if($from_id = $id){
$message_type = "SENT TO";}
else{
$message_type = "RECEIVED BY";}


echo "<tr>";

echo "<td>";
echo "<a href='profile.php?id=$to_user'>$pic_id</a>";
echo "</td>";

echo "<td>";
echo "<a href='profile.php?id=$to_user'>$firstname $lastname</a>";
echo "</td>";

echo "<td>";
echo "$message_type";
echo "</td>";

echo "<td>";
echo "<a href='message.php?id=$message_id&user=$id'><p id='title'>$title</p></a>";
echo "<p id='content'>$content</p>";
echo "</td>";

echo "<td>";
if (date("d, m, y", time()) != date("d, m, y", strtotime($message_date))   ) {
   print date('h:i A', strtotime($message_date)); }
else {
print "<p id='date'>";
   print  date('m/d/y', strtotime($message_date));
   print "</p>";
   print date('h:i A', strtotime($message_date));
   
}
echo "</td>";

echo "<td>";
echo "<a href='outbox.php?id=$message_id'>Delete</a>";
echo "</td>";

echo "</tr>";



} //close while






?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.