ecabrera Posted August 24, 2011 Share Posted August 24, 2011 this is part of my code and i need help because when user post a comment the comment is suppose to show there picture and other users picture that comment but insted it shows the users picture on every comment whats wrong with it echo " <a href='$site/profile?id=$user_id'> $user_name </a> <br> <a href='$site/profile?id=$user_id'> <img src='avatars/$avatar' width='70px' height='50px'><a href='$site/profile?id=$user_id'></a> <b> on $date</b><br />"; Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/ Share on other sites More sharing options...
msaz87 Posted August 24, 2011 Share Posted August 24, 2011 There's not enough information to go by in the code you provided. Where is $avatar defined? Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261617 Share on other sites More sharing options...
ecabrera Posted August 24, 2011 Author Share Posted August 24, 2011 <?php $getid=""; if(@$_GET['id']) $getid = $_GET['id']; if ($getid){ require('scripts/connect.php'); $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $firstname = $row['first_name']; $user = $row['username']; $bio = $row['bio']; $youtube = $row['youtube']; $title = "$firstname's Profile"; $meta_description = "$bio"; $meta_keywords = "$youtube"; } else $title = "Opps!! Profile not found!"; mysql_close(); } else $title = "Profiles"; ?> <?php require("styles/top.php"); ?> <div id='full'> <?php $msg=""; if (!$getid) $getid = "1"; require('scripts/connect.php'); $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $firstname = $row['first_name']; $lastname = $row['last_name']; $user = $row['username']; $email = $row['email']; $avatar = $row['avatar']; $bio = nl2br($row['bio']); $sex = $row['sex']; $status = $row['status']; $education = $row['education']; $music = $row['music']; $movies = $row['movies']; $tv = $row['tv']; $youtube = $row['youtube']; $lastlogin = $row['last_login']; $active = $row['active']; $locked = $row['locked']; $date = $row['date']; if ($locked == 0){ echo "<div id='profile'> <div id='leftside'> <img src='avatars/$avatar' width='200px' height='200px' style='border: 2px double #b1d0f0;'></img><table bordercolor='#b1d0f0' width='125' height='10' align='right' border='0'><tr><td><br/>$firstname <br />$sex <br />$status<br /> <br />Last Login: $lastlogin <br /> </tr> </table> <a href='#' id='MessageLink' rel='Message'><img src='images/message.gif' border='0' align='middle' /> <a href='#' id='AddFriendLink' rel='addtofriends'><img src='images/friend.gif' border='0' align='middle' /></a> <br><br /> <table id='Table1' bordercolor='#b1d0f0' cellspacing='0' cellpadding='0' width='300' bgcolor='#ffffff' border='1' class='interestsAndDetails'> <tbody><tr> <td class='text tdborder' valign='middle' align='left' width='300' bgcolor='#b1d0f0' wrap='' style='WORD-WRAP:break-word'> <FONT COLOR='black'><b>$firstname's Interests</b></FONT></td> </tr> <tr valign='top'> <td class='tdborder'> <table id='Table2' bordercolor='#000000' cellspacing='3' cellpadding='3' width='330' align='left' bgcolor='#b1d0f0' border='0'> <tbody> <tr> <td valign='top' align='left' width='30' bgcolor='#d5e8fb'><span class='lightbluetext8'>Movies:</span> </td> <td width='175' bgcolor='#d5e8fb' style='WORD-WRAP: break-word'> $movies </td> </tr> <tr> <td valign='top' align='left' width='30' bgcolor='#d5e8fb'><span class='lightbluetext8'>TV:</span> </td> <td width='175' bgcolor='#d5e8fb' style='WORD-WRAP: break-word'> $tv </td> </tr> <tr> <td valign='top' align='left' width='30' bgcolor='#d5e8fb'><span class='lightbluetext8'>Idk:</span> </td> <td width='175' bgcolor='#d5e8fb' style='WORD-WRAP: break-word'> Idk yeat </td> </tr> <tr> <td valign='top' align='left' width='30' bgcolor='#d5e8fb'><span class='lightbluetext8'>IdK:</span> </td> <td width='175' bgcolor='#d5e8fb' style='WORD-WRAP: break-word'> g </td> </tr> </tbody></table> </td> </tr> </tbody></table> </div> <div id='rightside'> <div> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div class='top'>$firstname's Profile</div> </div> <div class='bottom'> <b>Name</b> - $firstname $lastname<br /> <b>Gender</b> - $sex<br /> <b>Status</b> - $status<br /> <b>Education</b> - $education<br /> <b>Joined</b> - $date<br /> <b>Last Login</b> -$lastlogin<br />"; if ($youtube) echo "<br /><b>Youtube Channel:</b><br /> <a href='http://www.youtube.com/$youtube'>$youtube</a><br />"; if ($bio) echo "<br /><b>About Me:</b><br/>$bio<br/>"; echo "</div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; /* if ($youtube) echo "<script src='http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&up_channel=$youtube&synd=open&w=275&h=390&title=&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js'></script>"; */ /*ad will appear*/ echo "<table><tr><td><script type='text/javascript'> ch_client = 'jkj'; ch_width = 448; ch_height = 100; ch_type = 'mpu'; ch_sid = 'jDefault'; ch_backfill = 1; ch_color_site_link = '#0000CC'; ch_color_title = '#0000CC'; ch_color_border = 'transparent'; ch_color_text = '#000000'; ch_color_bg = 'transparent'; </script> <script src='http://scripts.j.net/eminimalls/amm.js' type='text/javascript'> </script></td></tr></table>"; /*music player*/ if ($music) echo "<table height=100px width=590px border='0'<tr> <td><b>Music Player:</b><br/>$music<br/></td> </tr> </table>"; echo "<a name='comments'></a><div style='margin-top: 15px;'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div class='top'>$firstname's Profile Comments</div> </div> <div class='bottom'>"; // comment button action if (@$_POST['commentbtn']){ if ($username){ $comment = $_POST['comment']; if(!empty($comment)){ $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' AND user_id='$userid' AND comment='$comment'"); $numerows = mysql_num_rows($query); if ($numrows != 0){ $commdate = date("F d, Y"); // October 08, 2010 mysql_query("INSERT INTO profile_comments VALUES ('', '$getid', '$userid', '$username', '$comment', '$commdate')"); // email profile owner $webmaster = "admin@mjoz.com"; $headers = "From:kjje jujkjz<$webmaster>"; $subject = "$username has commented on your profile"; $message = "Hello $firstname $lastname. $username has posted a comment on your profile on hjh.com"; $message .= " The message $username has posted with is below.\n"; $message .= "\n****************************************************************\n"; $message .= "$comment"; $message .= "\n\n****************************************************************\n\n"; $message .= "Click here to view $username's profile $site/profile?id=$userid\n"; $message .= "Click here to view your profile $site/profile?id=$getid\n"; // send email mail($email, $subject, $message, $headers); $msg = "Your comment has been added and is shown above."; } else $msg = "You can not submit the same comment twice."; } else $msg = "You did not supply a comment."; } else $msg = "You must be logged in to comment on profiles."; } // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br($row['comment']); $date = $row['date']; echo " <a href='$site/profile?id=$user_id'> $user_name </a> <br> <a href='$site/profile?id=$user_id'> <img src='avatars/$avatar' width='70px' height='50px'><a href='$site/profile?id=$user_id'></a> <b> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area // show comment nav echo "<div style='float: right;'>"; if (!($start <= 0)) echo "<a href='$site/profile?id=$getid&s=$prev#comments'>Previous</a>"; if (!($start > $numrows - $perpage)) echo "<a href='$site/profile?id=$getid&s=$next#comments'>Next</a>"; echo "</div>"; if ($username){ // display comment form echo "<a name='comment-form'></a>"; if ($msg) echo "<b>$msg</b><br />"; echo "<form action='$site/profile?id=$getid#comment-form' method='post'> <table> <tr> <td><textarea name='comment' style='width: 400px; height: 75px;'></textarea></td> </tr> <tr> <td><input type='submit' name='commentbtn' value='Comment'></td> </tr> </table> </form>"; } // end comment box echo "</div></div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; // end right column echo "</div>"; } else echo "<font color='red'><center><h1>The profile you have selected is currently locked.</h1></center></font>"; } else echo "No user was found."; ?> </div> <div id='left'> </div> <div id='right'> </div> <?php require("styles/bottom.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261618 Share on other sites More sharing options...
msaz87 Posted August 24, 2011 Share Posted August 24, 2011 You never define the commenter's avatar. It's only defined once, way above the comment section... so if anything, that's going to be the only avatar displayed for all the comments, since it's never changed in the loop. Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261620 Share on other sites More sharing options...
ecabrera Posted August 24, 2011 Author Share Posted August 24, 2011 can u show me how please Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261623 Share on other sites More sharing options...
ecabrera Posted August 25, 2011 Author Share Posted August 25, 2011 can some one help me or give me and example Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261640 Share on other sites More sharing options...
ecabrera Posted August 25, 2011 Author Share Posted August 25, 2011 help Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261759 Share on other sites More sharing options...
cyberRobot Posted August 25, 2011 Share Posted August 25, 2011 It sounds like you could use a LEFT JOIN which is used to get data from multiple tables with one query. This should hopefully help: http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1261818 Share on other sites More sharing options...
ecabrera Posted August 27, 2011 Author Share Posted August 27, 2011 i dont think that will work all i want to do is display others members avatar // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br($row['comment']); $date = $row['date']; echo " <a href='$site/profile?id=$user_id'> $user_name </a> <br> <a href='$site/profile?id=$user_id'> <img src='avatars/$avatar' width='70px' height='50px'><a href='$site/profile?id=$user_id'></a> <b> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area Quote Link to comment https://forums.phpfreaks.com/topic/245641-same-img/#findComment-1262566 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.