daled Posted July 12, 2007 Share Posted July 12, 2007 This makes me very angry because it worked for a while then decided not to work and now I have no idea what's wrong. What this is supposed to do display posts corresponding to a certain topic in a forum. If the "edit" conditions are met, it's supposed to change that post to a text box where the post can be edited. Poster names are a link to their profile page, their avatar is pulled from their database. Here's the problem. The code repeats as many times as I need it to, but I keep getting the same post over and over again instead of getting different posts. Here's my code: <?php if(isset($_GET['topic'])){ //member number query $query3 = sprintf("SELECT `member` FROM `bandinfo` WHERE `bandname` = '%s'", $row_result['poster']); $result3 = mysql_query($query3, $conn); $row_result3 = mysql_fetch_assoc($result3); $numrow_result3 = mysql_num_rows($result3); //header echo "<span class='topictitle2'>".$row_result['topictitle']."</span><br><br>"; echo "<center><b>started by:</b> <a href='profile.php?artist=".$row_result3['member']."'>".$row_result['poster']."</a> <B>on</b> ".$row_result['time'].", ".$row_result['date']."</center>"; echo $row_result['post']; echo '<hr width=100% size="1px" />'; //post query $query4 = sprintf("SELECT * FROM `forums` WHERE `topic` = '%s' AND `category` = 'post' ORDER BY `active` ASC", $_GET['topic']); $result4 = mysql_query($query4, $conn); $row_result4 = mysql_fetch_assoc($result4); $numrow_result4 = mysql_num_rows($result4); //no post return if($numrow_result4 == 0){ echo "<table bgcolor='#FFFFFF' width=100%><tr><td><center>This topic has no associated posts yet.</center></td></tr></table><hr width=100% size='1px' />"; }else{ //post repeat $num = 0; do { //member number query mysql_select_db("masterdatabase", $conn); $query6 = sprintf("SELECT `member` FROM `bandinfo` WHERE `bandname` = '%s'", $row_result4['poster']); $result6 = mysql_query($query6, $conn); $row_result6 = mysql_fetch_assoc($result6); $numrow_result6 = mysql_num_rows($result6); //avatar query mysql_select_db($row_result6['member'], $conn); $query5 = sprintf("SELECT `avatar` FROM `basicinfo`"); $result5 = mysql_query($query5, $conn); $row_result5 = mysql_fetch_assoc($result5); //even or odd ++$num; if(1&$num){ $bgcolor = "#ffffff"; }else if(!(1&$num)){ $bgcolor = "#999999"; }; //post return //edit link if($_COOKIE['number'] == $row_result6['member']){ $edit = "<a href='forums.php?topic=".$_GET['topic']."&action=edit&number=".$row_result4['number']."#".$row_result4['number']."'>Edit</a>"; }else{ $edit = NULL; }; //read post if(!isset($_GET['number']) or (isset($_GET['number']) and ($_GET['number'] != $row_result4['number']))){ echo' <a name="'.$row_result4 ['number'].'"> <table bgcolor="'.$bgcolor.'" width=100%> <tr> <td valign="top" width=20%> Post <b>#'.$num.'</b> by: <br> <a href="profile.php?artist='.$row_result6['member'].'">'.$row_result4['poster'].'</a> <br> <img src="'.$row_result5['avatar'].'" /> </td> <td width=80%> <B>'.$row_result4['time'].'</b> on <B>'.$row_result4['date'].'</b> <hr width=100% size="1px"> '.$row_result4['post'].' <hr width=100% size="1px"> '.$edit.' </td> </tr> </table> <hr width=100% size="1px" />'; //edit post }else if(isset($_GET['action']) and ($_GET['action'] == 'edit') and isset($_GET['number'])){ echo' <a name="'.$row_result4['number'].'"> <table bgcolor="'.$bgcolor.'" width=100%> <tr> <td valign="top" width=20%> Post <b>#'.$num.'</b> by: <br> <a href="profile.php?artist='.$row_result6['member'].'">'.$row_result4['poster'].'</a> <br> <img src="'.$row_result5['avatar'].'" /> </td> <td width=80%> <form action="process.php?action=editpost" method="POST"> <hr width=100% size="1px"> <textarea name="post" class="edittextbox">'.$row_result4['post'].'</textarea <hr width=100% size="1px"> <input type="submit" name="submit" value="Edit Post" class="submit"> <input type="hidden" name="number" value="'.$row_result4['number'].'"> <input type="hidden" name="cat" value="'.$row_result['cat'].'" /> <input type="hidden" name="sub" value="'.$row_result['sub'].'" /> <input type="hidden" name="topic" value="'.$row_result['topic'].'" /> <input type="hidden" name="topictitle" value="'.$row_result['topictitle'].'" /> </form> </td> </tr> </table> <hr width=100% size="1px" />'; }; } while ( $num <= $numrow_result4-1); }; //post form if(isset($_COOKIE['bandname']) and isset($_COOKIE['number'])){ echo' <form action="process.php?action=forumpost" method="POST"> <center> <textarea class="textbox" name="post"></textarea> <br> <input type="submit" class="submit" name="Submit" value="Submit Post" /> <input type="hidden" name="cat" value="'.$row_result['cat'].'" /> <input type="hidden" name="sub" value="'.$row_result['sub'].'" /> <input type="hidden" name="topic" value="'.$row_result['topic'].'" /> <input type="hidden" name="topictitle" value="'.$row_result['topictitle'].'" /> </center> </form> <br>'; }else{ echo "<center>You must be logged in to post!</center><br>"; }; }; ?> Thanks for anyone's help! Quote Link to comment https://forums.phpfreaks.com/topic/59710-solved-mysql-and-do-while/ Share on other sites More sharing options...
Oldiesmann Posted July 13, 2007 Share Posted July 13, 2007 You need to put $row_result4 = mysql_fetch_assoc($result4); inside the do ... while loop. Otherwise you're just pulling the first row from the query. Quote Link to comment https://forums.phpfreaks.com/topic/59710-solved-mysql-and-do-while/#findComment-296911 Share on other sites More sharing options...
daled Posted July 13, 2007 Author Share Posted July 13, 2007 IT WORKED!!! Thanks SO much! Quote Link to comment https://forums.phpfreaks.com/topic/59710-solved-mysql-and-do-while/#findComment-296932 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.