html - How to display user avatar next to post? (php,mysql) -
Therefore, two tables in my database are called users and another news Strong> I created it that users can add news posts to the site, but I could not display the user's image next to my post
this is my code now
& Lt ;? Php $ news = ""; $ User_id = ""; $ SqlCommand = "Select ID Order ID DESC Limit 10"; $ SqlCommand3 = "select from users"; $ Query = mysql_query ($ sqlCommand) or die (mysql_error ()); $ Query3 = mysql_query ($ sqlCommand3) or die (mysql_error ()); $ Count = mysql_num_rows ($ query); If ($ count> 1) {$ News = ""; While ($ line = mysql_fetch_array ($ query)) & amp; Amp;; ($ Row2 = mysql_fetch_array ($ query3))) {$ News = "& Lt; a href = \" news? Id = ". $ Row ['id']." \ "& Gt; div class = \" news-post \ "& gt; & lt; img src = \". $ Line 2 ['author_avatar']. "\" & Gt; & Lt; P & gt; $ Line ['author'] ".. & lt; h2 & gt; & lt" $ line ['title'] .. "; / H2>
] To resize the image from users' table
Before you $ $ a speech mark ("line 2 ['author_avatar'].
1) {$ News. = ""; While ($ line = mysql_fetch_array ($ query)) & amp; $ Row2 = mysql_fetch_array ($ query3))) {$ News. = "& Lt; a href = \" news? Id = ". $ Row ['id']." \ "& Gt; div class = \" news-post \ "& gt; & lt; img src =" \ ". $ Row2 ['author_avatar']." \ "& Gt; & lt; p & gt; $ Line ['author']. "& Lt; / p> & lt; h2 & gt; $ Line ['title'] " & gt;"; } // when closing} and {$ news = "no news!"; }? & Gt;
Instead of having two SQL queries described by Andrasi, you should see the INER JOIN. There is a good tutorial about how to use it.
Comments
Post a Comment