Jump to content

Recommended Posts

Got a problem i can`t solve hope some1 can help.

<?php
session_start();
include_once "includes/db_connect.php";
include_once "includes/functions.php";
include 'includes/smile.php';
logincheck();
$username=$_SESSION['username'];
echo "<link href=includes/in.css rel=stylesheet type=text/css> ";
$username=$_SESSION['username'];
$mysql=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($mysql);
$id=$_GET['view'];
$delete_id=$_POST['delete_id'];
$delete=$_POST['delete'];
$inbox=mysql_query("SELECT * FROM `messages` WHERE `id`='$id'");
if($reply){
}
if($delete){
mysql_query("DELETE FROM `messages` WHERE `id`='$id'");
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=inbox.php\">";
}
$image1 = mysql_query("SELECT * FROM users WHERE id='$inbox->from");
$im = mysql_fetch_object($image1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #111111;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(images/pattern.png)
}
.orange_status {
color: #F28900;
font-weight: bold;
font-size: 11px;
font-family: Verdana;
}
.standard_status {
color: #FFFFFF;
font-family: Verdana;
font-size: 11px;
}
.highlight_status {color: #eeeeee; font-family: Verdana; font-size: 8pt; 
}

.input_table {border:1px solid #232323;  
background-color:#111111;
}
.body, td, th {
font-family: Verdana;
font-size: 11px;
        text-decoration: none;
color: #FFFFFF;
}
.td {
font-family: Verdana;
font-size: 11px;
        text-decoration: none;
color: #FFFFFF;
}
.th {
font-family: Verdana;
        text-decoration: none;
font-size: 11px;
color: #FFFFFF;
}
.title {
font-family: Verdana;
    text-decoration: none;
font-size: 11px;
    color: #D5D5D5;
    font-weight: bold;
}
.menu_content {font-size: 11px}
.text_box {
background-image:url(http://img128.imageshack.us/img128/7606/txtboxdz4.gif);
background-repeat:repeat-x;
background-color: White;
color:Black;
border:1px solid #000000;  
font-family: Verdana;
font-size: 11px;
height: 20px;
}
.input_table1 {border:1px solid #232323;  
background-color:#111111;
}
a:link {
color: #d5d5d5;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #d5d5d5;
}
a:hover {
text-decoration: none;
color: #d5d5d5;
}
.abutton{
font-weight: bold;
font-family: Verdana;
font-size: 11px;
color: #FFFFFF;
border:1px solid black;
height:19px;
background: #000000 url(http://img299.imageshack.us/img299/8672/mwbuttongradvy6.gif) repeat-x;
}
-->
</style>
</head>
<body>



<table width="400" height="98" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" bgcolor="#111111" class="thinline">
<? while($messages = mysql_fetch_object($inbox)){ ?>
<tr>
<td height="20" colspan="2" background="includes/grad.jpg" bgcolor=#222222><strong>From</strong> <a href='Profile2.php?viewuser=<? print"$messages->from"; ?>'><? print"$messages->from"; ?></a> <? print"$messages->date"; ?></td>
</tr>
<tr>
<td height="25" colspan="2" background="includes/gradgrey.jpg" bgcolor=#222222><strong>Subject:</strong> <? print"$messages->subject"; ?></td>
</tr>
<tr>
<td width="87" height="25" align="center" bgcolor=#222222><img src="<? print"$im->image"; ?>" width='70' height='70' border='1' /></td>
<td width="299" height="25" valign="top" bgcolor=#222222><? echo replace($messages->message); ?></td>
</tr>
<tr>
<td height="25" colspan="2" bgcolor="#222222"><form id="form2" name="form2" method="post" action="">
<input name="delete_id" type="hidden" value="<? print"$messages->id"; ?>" /><input name="delete" type="submit" class="abutton" value="Delete This Message" /></form>
<form id="form3" name="form3" method="post" action="send.php?fromper=<? print"$messages->from"; ?>&fsubject=RE:<? print"$messages->subject"; ?>&reply=<? print"$messages->id"; ?>">
<input name="reply_name" type="hidden" value="<? print"$mail->from"; ?>"><input name="reply" type="submit" class="abutton" value="Reply To This Message" />
</form></td>
<tr>
<td height="25" colspan="2" align="center" bgcolor="#222222"><a href="inbox.php" target="_self">Back To Your Inbox
</a></td>
</tr>
<? 
mysql_query("UPDATE `messages` SET `read`='1' WHERE `id`='$messages->id'");
}
?>
</table>
</html>

 

This is the message i am trying to sort out it works thats fine but i want my user avater on the message but the image is in the users data base how can i make it show the avater on the message from the users database but join the two if that makes some sence i have tried to do it myself and thats what ive came up with..

Thank You!

Link to comment
https://forums.phpfreaks.com/topic/169500-help-with-message-and-avater/
Share on other sites

Simply select it from the database using the userId. The message contains the userId, correct? Use a left join on the query. Example

 

SELECT m.*,a.filename FROM messages m LEFT JOIN avatars a ON (m.userId=a.userId) WHERE m.id='123'

Ok you have to take the post as an example and modify the query to fit your design. You require a foreign key on the messages table to join it to a user. How do you currently know what messages belong to a user?

 

Normalised design example

 

users

====

userId

image

 

messages

=======

messageId

userId

message

 

Many messages can belong to one user. This is called a one to many relationship and is defined on the key userId.

$fetch = mysql_fetch_object($mysql);
print $fetch->image;

 

You may want to look at your variable naming. Your names don't make any sense to an onlooker.

$mysql is very generic as it $fetch

 

$queryResult = mysql_query("SELECT abc FROM table");
while($row = mysql_fetch_object($queryResult)) {
  print $row->abc."<br />";
}

 

If you have more than 1 query then name the variable results accordingly ie. $userQueryResult, $messageQueryResult

I Think i Have sorted it but nothin at all is showing up now i think ive missed a bracket or something

<?php
session_start();
include_once "includes/db_connect.php";
include_once "includes/functions.php";
include 'includes/smile.php';
logincheck();
$username=$_SESSION['username'];
echo "<link href=includes/in.css rel=stylesheet type=text/css> ";
$username=$_SESSION['username'];
$mysql=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($mysql);
$id=$_GET['view'];
$delete_id=$_POST['delete_id'];
$delete=$_POST['delete'];
$inbox=mysql_query("SELECT * FROM `messages` WHERE `id`='$id'");
if($reply){
}
if($delete){
mysql_query("DELETE FROM `messages` WHERE `id`='$id'");
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=inbox.php\">";
}
$inbox=mysql_query("$inbox");
$num=mysql_num_rows($inbox);
while($right=mysql_fetch_object($inbox)){

$inbox = mysql_query("SELECT * FROM users WHERE username = '$right->username'");
$in = mysql_fetch_object($inbox);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #111111;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(images/pattern.png)
}
.orange_status {
color: #F28900;
font-weight: bold;
font-size: 11px;
font-family: Verdana;
}
.standard_status {
color: #FFFFFF;
font-family: Verdana;
font-size: 11px;
}
.highlight_status {color: #eeeeee; font-family: Verdana; font-size: 8pt; 
}

.input_table {border:1px solid #232323;  
background-color:#111111;
}
.body, td, th {
font-family: Verdana;
font-size: 11px;
        text-decoration: none;
color: #FFFFFF;
}
.td {
font-family: Verdana;
font-size: 11px;
        text-decoration: none;
color: #FFFFFF;
}
.th {
font-family: Verdana;
        text-decoration: none;
font-size: 11px;
color: #FFFFFF;
}
.title {
font-family: Verdana;
    text-decoration: none;
font-size: 11px;
    color: #D5D5D5;
    font-weight: bold;
}
.menu_content {font-size: 11px}
.text_box {
background-image:url(http://img128.imageshack.us/img128/7606/txtboxdz4.gif);
background-repeat:repeat-x;
background-color: White;
color:Black;
border:1px solid #000000;  
font-family: Verdana;
font-size: 11px;
height: 20px;
}
.input_table1 {border:1px solid #232323;  
background-color:#111111;
}
a:link {
color: #d5d5d5;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #d5d5d5;
}
a:hover {
text-decoration: none;
color: #d5d5d5;
}
.abutton{
font-weight: bold;
font-family: Verdana;
font-size: 11px;
color: #FFFFFF;
border:1px solid black;
height:19px;
background: #000000 url(http://img299.imageshack.us/img299/8672/mwbuttongradvy6.gif) repeat-x;
}
-->
</style>
</head>
<body>



<table width="400" height="98" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" bgcolor="#111111" class="thinline">
<? while($messages = mysql_fetch_object($inbox)){ ?>
<tr>
<td height="20" colspan="2" background="includes/grad.jpg" bgcolor=#222222><strong>From</strong> <a href='Profile2.php?viewuser=<? print"$messages->from"; ?>'><? print"$messages->from"; ?></a> <? print"$messages->date"; ?></td>
</tr>
<tr>
<td height="25" colspan="2" background="includes/gradgrey.jpg" bgcolor=#222222><strong>Subject:</strong> <? print"$messages->subject"; ?></td>
</tr>
<tr>
<td width="87" height="25" align="center" bgcolor=#222222><img src='<? print'$in->image'; ?>' width='70' height='70' border='1' /></td>
<td width="299" height="25" valign="top" bgcolor=#222222><? echo replace($messages->message); ?></td>
</tr>
<tr>
<td height="25" colspan="2" bgcolor="#222222"><form id="form2" name="form2" method="post" action="">
<input name="delete_id" type="hidden" value="<? print"$messages->id"; ?>" /><input name="delete" type="submit" class="abutton" value="Delete This Message" /></form>
<form id="form3" name="form3" method="post" action="send.php?fromper=<? print"$messages->from"; ?>&fsubject=RE:<? print"$messages->subject"; ?>&reply=<? print"$messages->id"; ?>">
<input name="reply_name" type="hidden" value="<? print"$mail->from"; ?>"><input name="reply" type="submit" class="abutton" value="Reply To This Message" />
</form></td>
<tr>
<td height="25" colspan="2" align="center" bgcolor="#222222"><a href="inbox.php" target="_self">Back To Your Inbox
</a></td>
</tr>
<? 
mysql_query("UPDATE `messages` SET `read`='1' WHERE `id`='$messages->id'");
}
?>
</table>
</html>	

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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