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
user_id username (shortened table)
92 kkjay
95 njama
"wid_updates"
[PK=update_id, (FK=user_id, attached_picture_id)]
update_id update_text attached_picture_id user_id
26 Done dana 24 92
27 Qzzz. 25 92
29 Psys guys 26 95
31 I am fine null 92
"picture"
[PK=picture_id, FK=user_id]
picture_id picture_url picture_thumb_url user_id avatar
24 ../Pictures/90.png ../Pictures/Thumbs/90.png 92 1
25 ../Pictures/811.jpg ../Pictures/Thumbs/811.jpg 92 0
26 ../Pictures/641.jpg ../Pictures/Thumbs/641.jpg 95 0
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
$user_id = $_SESSION['UserSession'];
//query user avatar
mysql_select_db($database_connections, $connections);
$query_avatar_thumb = "SELECT picture_thumb_url FROM picture WHERE user_id='$user_id' AND avatar='1'";
$avatar_thumb_result = mysql_query($query_avatar_thumb) or die(mysql_error());
$avatar_thumb = mysql_fetch_assoc($avatar_thumb_result);
//query username
$query_user_info = "SELECT username FROM users WHERE user_id='$user_id'";
$user_info = mysql_query($query_user_info, $connections) or die(mysql_error());
$row_user_info = mysql_fetch_assoc($user_info);
//query update image
$query_wid_updates = "SELECT update_text, picture_thumb_url FROM wid_updates JOIN picture ON wid_updates.user_id = '$user_id'
AND wid_updates.attached_picture_id = picture.picture_id OR wid_updates.attached_picture_id IS NULL 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 avatar field is set to 1 if it is the profile picture of a user and set to null when it is not. When I upload an update with no update picture, I get a display of that update 3 times with all the 3 pics in the picture table.
Another question, when doing a search because I intend to make it a social network web app, how will I make a query that will return a thumb for a particular user that is being searched for based on the table.
Thanks in advance.