I Am Java Posted June 14, 2010 Share Posted June 14, 2010 http://ddf.pastebin.com/CD5XQrYV How can I make that a bit more efficient? Right now I use a while statement to add up $m, which gives a count of how many unread topics there are, and if there are more than 1, then it displays a link. If not, it displays nothing. Right now, since there are 15 forums, the script takes well over 30 seconds to run. How can I count up the amount of unread topics faster? Thanks. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 14, 2010 Share Posted June 14, 2010 I'm not certain how your database is configured, but wouldn't it be easier to do all the checking on the database? SELECT COUNT(*) AS `total` FROM `forum_thread` WHERE `thread_boardid`='$boardid' AND `read` LIKE '%$logged_id%' Here's the modified version: <?php while($board = mysql_fetch_array($r2)){ $r3 = mysql_query("SELECT * FROM `forum_thread` WHERE `thread_boardid` = '".$board['board_id']."' AND `thread_deleted` = '0' ORDER BY `thread_id` DESC") or die(mysql_error()); $thread_count = mysql_num_rows($r3); $title_get3 = stripslashes($board['board_name']); $title3 = str_replace($title_current,$title_replace,$title_get3); echo " <tr> <td style='text-align:center;'> "; if($logged['userlevel']=='9'){ $boardid = $board['board_id']; $logged_id = $logged['id']; $get_new2 = mysql_query("SELECT COUNT(*) AS `total` FROM `forum_thread` WHERE `thread_boardid`='$boardid' AND `read` LIKE '%$logged_id'") or die(mysql_error()); $m = 1; $row = mysql_fetch_assoc($get_new2); $total = $row['total']; } echo $total; if($total != '0' && $logged['userlevel'] == '200'){ echo " <a href='".$url."forums".$a_act."markread".$a_view.$board['board_id'].$end."'>NEW</a> "; } else { echo " "; } ?> Remember: this is a concept code, so you will need to change it to fit your needs, but if I understand what you are needing, that should be the way you want to go: 1) find all threads that are unread for that user 2) if there is anything unread, show them a link to mark them read. Quote Link to comment Share on other sites More sharing options...
ignace Posted June 14, 2010 Share Posted June 14, 2010 1. while($board=mysql_fetch_array($r2)){ $r3=mysql_query("SELECT * FROM `forum_thread` WHERE `thread_boardid` = '".$board['board_id']."' AND `thread_deleted` = '0' ORDER BY `thread_id` DESC") or die(mysql_error()); This is the equivalent of a JOIN, use it: SELECT * FROM forum_thread JOIN forum_board ON forum_thread.thread_boardid = forum_board.board_id ORDER BY thread_id DESC Quote Link to comment 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.