Hi Guys,
Aplologies for the length but I wanted to be clear.
I'm trying to make a website where people can update their status's (like facebook). Just learning PHP. I have added a functionality whereby one can update their status(text only) or can update their status(text and upload a photo for that status). I have been able to do this but after updating, the difficulty is showing one's previous updates in the form of:
avatar pic - update text - update image(if image)
avatar pic - update text - default image(if update image not uploaded)
default avatar pic - update text - default image(if update image not uploaded)
with the latest updates first and then the rest in descending order.
If all updates for a user have update pics(ie. wid_updates.attached_picture_is not null, then I do not have a problem. If a user does not put up a pic update, then all hell breaks loose when returning previous updates.
MY TABLES:
"users"
[PK=user_id, FK=user_avatar_id]
user_id username user_avatar_id,(shortened table)
92 kkjay 24
95 njama null
"wid_updates"
[PK=update_id, (FK=user_id, attached_picture_id)]
update_id update_text attached_picture_id user_id timestamp
26 Done dana 24 92 2011-01-05 12:39:27
27 Qzzz. 25 92 2011-01-05 12:42:18
29 Psys guys 26 95 2011-01-05 13:50:54
31 I am fine null 92 2011-01-05 15:41:52
"picture"
[PK=picture_id, FK=user_id]
picture_id picture_url picture_thumb_url user_id
24 ../User_Pictures/9042.png ../User_Pictures/Thumbs/9042.png 92
25 ../User_Pictures/81104.jpg ../User_Pictures/Thumbs/81104.jpg 92
26 ../User_Pictures/64124.jpg ../User_Pictures/Thumbs/64124.jpg 95
NB:Update pics are first saved into pictures table then their picture_id saved into the wid_updates table as attached_pic_id foreign key.
My PHP query:
<?php require_once('Connections/connections.php'); ?>
<?php
//query user_avatar_id and user_id
$username = $_SESSION['UserSession'];
$query_user_info = "SELECT user_avatar_id, user_id FROM users WHERE username='$username'";
$user_info_result = mysql_query($query_user_info) or die(mysql_error());
$user_info = mysql_fetch_assoc($user_info_result);
$avatar_id = $user_info['user_avatar_id'];
$user_id = $user_info['user_id'];
//query avatar thumb from pictures
$query_avatar_thumb = "SELECT picture_thumb_url FROM picture WHERE picture_id='$avatar_id'";
$avatar_thumb_result = mysql_query($query_avatar_thumb) or die(mysql_error());
$avatar_thumb = mysql_fetch_assoc($avatar_thumb_result);
//query update image
$query_wid_updates = "SELECT update_text, picture_thumb_url FROM wid_updates JOIN picture ON
(wid_updates.user_id = $user_id && wid_updates.attached_picture_id = picture.picture_id) ORDER BY wid_updates.update_id DESC";
$wid_updates = mysql_query($query_wid_updates, $connections) or die(mysql_error());
$row_wid_updates = mysql_fetch_assoc($wid_updates);
?>
The display:
<?php do { ?>
<table width="460" border="0">
<tr>
<td height="50" width="50"><a href="profile.php"><img src="Images/<?php echo $avatar_thumb['picture_thumb_url']; ?>"
height="50" width="50" border="0"/></a></td>
<td width="360" colspan="3" class="overide" id="update_box"><div><?php echo $row_wid_updates['update_text']; ?></div></td>
<td width="50"><a href="pictures.php"><img src="Images/<?php echo $row_wid_updates['picture_thumb_url']; ?>"
height="50" width="50" border="0"/></a></td>
</tr>
<tr>
<td width="50" height="30"></td>
<td width="120"></td>
<td width="120" class="ordinary_text_12_green">Comment</td>
<td width="120"></td>
<td width="50"></td>
</tr>
</table>
<?php } while ($row_wid_updates = mysql_fetch_assoc($wid_updates)); ?>
The results I get are wid_updates 27 and 26 together with the avatar and update images. The null update (31) cannot be seen. Please help. I've spent most of the day trying and nothing. I appreciate any help.