Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying descending order status updates with avatar image and update image
    primarykey
    data
    text
    <p>Apologies 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:</p> <p>avatar pic - update text - update image(if image)</p> <p>avatar pic - update text - default image(if update image not uploaded)</p> <p>default avatar pic - update text - default image(if update image not uploaded)</p> <p>with the latest updates first and then the rest in descending order.</p> <p>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.</p> <p>Users table:</p> <pre><code>user_id, first_name, last_name, tel_no, address, username etc. </code></pre> <p>Wid_pdates table:</p> <pre><code>update_id, update_text, attached_picture_id, user_id, timestamp </code></pre> <p>Pictures table:</p> <pre><code>picture_id, picture_url, picture_thumb_url, user_id, avatar(bit) </code></pre> <p>The avatar bit is default 0 and set to 1 if it is the users avatar(profile) picture.</p> <p>My PHP code:</p> <pre><code>&lt;?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); ?&gt; </code></pre> <p>If all updates have a picture, then everything is good. if one update does not have a picture that update is displayed the same number of times as the no. of pictures in the pictures table , each pic included. If there are 4 pics in pictures, the text update without image will be returned 4 times with each of the pics attached.</p> <p>What is wrong? Any help appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload