I need help fetching user group codes and then showing post for those groups with PHP and MySQL -
the code have works, there problem can't sort data id because of way it's fetching group codes. here's code:
function displayoverview(){ global $database; global $session; $q = "select username, group_code " ."from classes username = '".$session->username."'"; $result = $database->query($q); /* error occurred, return given name default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "error displaying info"; return; } if($num_rows == 0){ echo '<div id="container"><div id="float_left"><img src="profile_pics/default.gif" class="image3" width="50" height="50" border="0"></div> <div id="float_right"><div id="container2"><div class="bubble"> <p class="user_name"></p> <p class="time">error name | <?php echo date("f j, y, g:i a"); ?></p> <p class="post">error messages.</p> <!-- <p class="attachments"><img src="images/attachment.png" width="20" height="20"><b>attatchmentments</b><br></p> --> </div></div></div></div>'; return; } /* display table contents */ for($i=0; $i<$num_rows; $i++){ $group_code = mysql_result($result,$i,"group_code"); $q2 = "select id, username, post, date, group_code, type, attachment_1, attachment_2 " ."from posts group_code = '".$group_code."'"; $result2 = $database->query($q2); /* error occurred, return given name default */ $num_rows2 = mysql_numrows($result2); for($i2=0; $i2<$num_rows2; $i2++){ $uname2 = mysql_result($result2,$i2,"username"); $post = mysql_result($result2,$i2,"post"); $type = mysql_result($result2,$i2,"type"); $userinfo2 = $database->getuserinfo2($uname2); $userinfo3 = $database->getuserinfo3($uname2); $full_name = $userinfo2['full_name']; $profile_img = $userinfo2['profile_img']; } } }
i have stuck, there way retrieve group codes call mysql database , find out groups user in , return post groups
you can in 1 query, join
ing 2 tables this:
select c.username, c.group_code, p.id, p.post, p.date, p.type, ... classes c inner join posts p on c.group_code = p.group_code c.username = ... order p.id;
Comments
Post a Comment