slyte33 Posted October 27, 2009 Share Posted October 27, 2009 Hello everyone, this is a forum script i've been working on for my rpg game, but I have a problem.. The while loop is looping each row in the table "forumposts" twice, and i cannot figure out why. Here is my code: <? include("lib.php"); $title = "Forums"; $player = check_user($secret_key, $db); include("templates/private_header.php"); include("use/housetable.php"); ?> <? function bbcode($text){ $text = str_replace('[br]', '<br>', $text); $text = str_replace('[b]', '<b>', $text); $text = str_replace('[/b]', '</b>', $text); $text = str_replace('[i]', '<i>', $text); $text = str_replace('[/i]', '</i>', $text); $text = str_replace('[u]', '<u>', $text); $text = str_replace('[/u]', '</u>', $text); $text = str_replace('[img]', '<img src="', $text); $text = str_replace('[/img]', '">', $text); $text = str_replace('[b]', '<b>', $text); $text = str_replace('[/b]', '</b>', $text); $text = str_replace('[i]', '<i>', $text); $text = str_replace('[/i]', '</i>', $text); $text = str_replace('[u]', '<u>', $text); $text = str_replace('[/u]', '</u>', $text); $text = str_replace('[url=', '<a href="', $text); $text = str_replace('[/url]', '</a>', $text); $text = str_replace('[img]', '<img src="', $text); $text = str_replace('[/img]', '">', $text); $text = str_replace('[color=red]', '<font color=red>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=green]', '<font color=green>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=purple]', '<font color=purple>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=orange]', '<font color=orange>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=brown]', '<font color=brown>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=yellow]', '<font color=yellow>', $text); $text = str_replace('[/color]', '</font>', $text); $text = str_replace('[color=blue]', '<font color=blue>', $text); $text = str_replace('[/color]', '</font>', $text); $text = nl2br($text); $text = trim($text); return $text; } ?> <style> a{color:black;text-decoration:bold;}a:hover{color:green;} .maintable {border-collapse:separate;border-spacing:2; } td.post { width: 150px; border-right: 1px solid #bea682; border-bottom: 1px solid #bea682; padding: 3px 5px; background-color: #ebe5cb; font-size: 11px; } td.post2 { border-right: 1px solid #bea682; border-bottom: 1px solid #bea682; padding: 3px 5px; background-color: #ebe5cb; font-size: 11px; } td.forum-title { background-color: #d6caa2; border-right: 1px solid #bea682; border-bottom: 1px solid #bea682; padding: 5px; font-weight: bold; font-size: 11px; } </style> <? if ($_GET['topicid']) { $query = $db->execute("update forumthreads set viewers=CONCAT(viewers,'($player->id)') where topicid=".$_GET['topicid']." && viewers NOT LIKE '%(".$player->id.")%'"); $limit = (!isset($_GET['limit']))?intval($setting->members_default_limit):intval($_GET['limit']); //Use default limit or user-selected limit if(!$limit) $limit=2; $query2 = $db->execute("select * from forumposts, forumthreads where forumthreads.topicid=forumposts.topicid and forumposts.topicid=$_GET[topicid]"); $page = (intval($_GET['page']) == 0)?1:intval($_GET['page']); //Start on page 1 or $_GET['page'] $begin = ($limit * $page) - $limit; //Starting point for query $total_players = $db->getone("select count(topicid) as `count` from `forumposts` where `topicid`=?", array($_GET['id'])); $queryr = $db->execute("select * from forumposts, forumthreads where forumthreads.topicid=forumposts.topicid and forumposts.topicid=$_GET[topicid] order by forumposts.repliedtime"); if ($queryr->recordcount() < 1) { echo "<center>Error"; include("use/endtable.php"); echo "</table>"; include("templates/private_header2.php"); exit; } $postd = $query2->fetchrow(); ?> <table> <tr> <td class='forum-title' colspan='2' valign='middle'><?=$postd[topic]?>(</font></td></tr> <? while ($post = $queryr->fetchrow()) { $user = $db->GetOne("select `username` from `players` where `id`=?", array($post['poster_id'])); $online = $db->GetOne("select `last_active` from `players` where `id`=?", array($post['poster_id'])); $rank = $db->GetOne("select `rank` from `players` where `id`=?", array($post['poster_id'])); $image = $db->GetOne("select `image` from `players` where `id`=?", array($post['poster_id'])); echo "<tr><td class=post><a href=profile.php?id=$post[poster_id]><center>$user</a></td><td class='post2'>test</td></tr><tr><td class=post rowspan=2 valign=top align=center> "; echo "<center><img src=$image width='123' height='98' align='bottom'></a><br>$rank<br><br>Posts: 930<br>Level: 23</td><td class='post2' height='150' valign='top'>"; ?> <?=bbcode($post[message])?> <br> </td> </tr> <tr> <td class='post2' height='1' valign='middle'> d </td></tr> <?}?> </table> <? include("use/endtable.php"); echo "</table>"; include("templates/private_header2.php"); exit; } if ($_GET['id']) { $topics = $db->execute("select * from forumtopics where id=$_GET[id]"); $listtopics = $db->execute("select * from forumthreads where topicid=$_GET[id]"); if ($topics->recordcount() < 1) { echo "<center>Error"; include("use/endtable.php"); echo "</table>"; include("templates/private_header2.php"); exit; } echo "<table><tr bgcolor=ebd297><td class=post2 width=1%></td><td><b>Topic</b></td><td><b>Starter</b></td><td><b>Posts</b></td><td><b>Views</b></td><td><b>Last Poster</b></td></tr>"; $bool = 1; while($topic = $listtopics->fetchrow()) { $viewed=explode("(",$topic['viewers']); $viewed=str_replace(")","",$viewed); if(!in_array($player->id, $viewed)) { $color = "D99126"; }else{ $color = ""; } $user = $db->GetOne("select username from players where id=$topic[player_id]"); $lpost = $db->GetOne("select username from players where id=$topic[lastpost]"); $viewed=explode("(",$topic['viewers']); $viewed=str_replace(")","",$viewed); echo "<tr class=\"row" . $bool . "\">\n"; if(!in_array($player->id, $viewed)) { echo "<td bgcolor=$color>"; echo "<img src=http://foarpg.com/forums/styles/bladev10/imageset/topic_unread_hot.gif></img>"; } else { echo "<td bgcolor=$color>"; echo "<img src=http://foarpg.com/forums/styles/bladev10/imageset/topic_read.gif></img>"; } echo "<td bgcolor=$color>"; echo "<a href=forumsjam.php?id=$_GET[id]&topicid=$topic[id]><b>$topic[topic]</b></a>"; echo "<td bgcolor=$color><a href=profile.php?id=$topic[player_id]>$user</a>"; echo "<td bgcolor=$color>$topic[posts]"; echo "<td bgcolor=$color>$topic[views]"; echo "<td bgcolor=$color>$lpost"; echo "</td></tr>"; $bool = ($bool==1)?2:1; } echo "</table>"; include("use/endtable.php"); echo "</table>"; include("templates/private_header2.php"); exit; } echo "<table><tr bgcolor=ebd297><td><b>Forum Name</b></td><td><b>Topics</b></td><td><b>Last Poster</b></td></tr>"; $query = $db->execute("select * from forumtopics"); $bool = 1; while($f = $query->fetchrow()) { $numtopics = $db->execute("select * from forumthreads where topicid=$f[id]"); echo "<tr class=\"row" . $bool . "\">\n"; echo "<td>"; echo "<a href=forumsjam.php?id=$f[id]>$f[name]</a><br>"; echo "<td>"; echo $numtopics->recordcount(); echo "<td>$f[lastpost]"; echo "</td></tr>"; $bool = ($bool==1)?2:1; } echo "</table>"; include("use/endtable.php"); echo "</table>"; include("templates/private_header2.php"); ?> The code is a bit messy, because i haven't got to around creating functions and organizing everything yet, but you can see where I have put my while loop 1 time, not 2 Link to comment https://forums.phpfreaks.com/topic/179216-solved-while-loop-is-looping-twice/ Share on other sites More sharing options...
slyte33 Posted October 27, 2009 Author Share Posted October 27, 2009 Nevermind, i fixed it Link to comment https://forums.phpfreaks.com/topic/179216-solved-while-loop-is-looping-twice/#findComment-945560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.