Jump to content

[SOLVED] mysql and do-while


daled

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.