Permalink
Browse files

Avoid using num_rows(), count in PHP

Refs #1117.
  • Loading branch information...
franzliedke committed Nov 25, 2018
1 parent 1aef372 commit 6bdf4f55bcb9c303afa8491edee394b59908e590
Showing with 14 additions and 4 deletions.
  1. +14 −4 moderate.php
@@ -491,7 +491,12 @@
}
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.post_topics IS NULL OR fp.post_topics=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) < 2)
$forums = array();
while ($row = $db->fetch_assoc($result))
$forums[] = $row;
if (count($forums) < 2)
message($lang_misc['Nowhere to move']);
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
@@ -513,7 +518,7 @@
<?php
$cur_category = 0;
while ($cur_forum = $db->fetch_assoc($result))
foreach ($forums as $cur_forum)
{
if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
{
@@ -563,11 +568,16 @@
// Verify that the topic IDs are valid (redirect links will point to the merged topic after the merge)
$result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $topics).') AND forum_id='.$fid.' ORDER BY id ASC') or error('Unable to check topics', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) != count($topics))
$tids = array();
while ($cur_tid = $db->result($result))
$tids[] = $cur_tid;
if (count($tids) != count($topics))
message($lang_common['Bad request'], false, '404 Not Found');
// The topic that we are merging into is the one with the smallest ID
$merge_to_tid = $db->result($result);
$merge_to_tid = $tids[0];
// Make any redirect topics point to our new, merged topic
$query = 'UPDATE '.$db->prefix.'topics SET moved_to='.$merge_to_tid.' WHERE moved_to IN('.implode(',', $topics).')';

0 comments on commit 6bdf4f5

Please sign in to comment.