CODE
<?php
include ('connect.php');
$result = mysql_query("SELECT * FROM user_post ORDER BY id DESC LIMIT 5");
while($row = mysql_fetch_array($result))
$avatar = mysql_query("SELECT * FROM users_info WHERE username=".$row['username']."");
$show = mysql_fetch_array($avatar);
{
echo "<div><img src=\"".$show['avatar']."\" width=\"100\" height=\"100\" style=\"float:left; margin-right:5px;\">".$row['username']." the ".$row['date']." <a href=\"#\">Read More...</a></div>";
}
mysql_close($con);
?>
include ('connect.php');
$result = mysql_query("SELECT * FROM user_post ORDER BY id DESC LIMIT 5");
while($row = mysql_fetch_array($result))
$avatar = mysql_query("SELECT * FROM users_info WHERE username=".$row['username']."");
$show = mysql_fetch_array($avatar);
{
echo "<div><img src=\"".$show['avatar']."\" width=\"100\" height=\"100\" style=\"float:left; margin-right:5px;\">".$row['username']." the ".$row['date']." <a href=\"#\">Read More...</a></div>";
}
mysql_close($con);
?>
Basically what i am trying to do, is my user posted a message, the first QUERY shows the last 5 posts by users. In my USER_POST table there is the post, the id, the username, the date.
What i want is to display the username, the date and the avatar of the user that posted the message. To do that i need to retrieve the info from the USERS_INFO table matching the USERNAME and selecting the avatar... that's what the second query is for. (called $avatar).
If i remove the query AVATAR the script works just fine, it displays the five LAST posts from my users and shows me the date and the link... but i want to have there AVATARS next to it, so i made something up and it says :
QUOTE
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/23/d222196706/htdocs/rabfly/index.php on line 29
Line 29 is the AVATAR fetch array. I am guessing its because this :
CODE
FROM users_info WHERE username=".$row['username']."");
Is not possible ? i mean username=".row['username']."
______________________
My idea was that when the user posts, i create a new row called useravatar, and in a hidden field in my form it echos the users avatar's link. and i just have to retrieve that link from the same query.... but imagine the user changes his avatar ? The script will keep his OLD avatar since its saved in the table user_post and not in users_info so it will not update....
Booooooooo am i going crazy ? Do i make any sense ?