Fix $db->result and replace to $db->fetch_row

This commit is contained in:
Visman 2023-10-18 18:41:09 +07:00
parent 548209139f
commit c7f6b5ab18
7 changed files with 18 additions and 14 deletions

View File

@ -844,7 +844,7 @@ function delete_post(int $post_id, int $topic_id)
// Count number of replies in the topic
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
$num_replies = $db->result($result, 0) - 1;
$num_replies = $db->result($result) - 1;
// If the message we deleted is the most recent in the topic (at the end of the topic)
if ($last_id == $post_id)

View File

@ -52,7 +52,7 @@ if (isset($_POST['action2']))
// Count number of replies in the topic
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'pms_new_posts WHERE topic_id='.$cur_post['tid']) or error('Unable to fetch post count', __FILE__, __LINE__, $db->error());
$num_replies = $db->result($result, 0) - 1;
$num_replies = $db->result($result) - 1;
$mquery[] = 'replies='.$num_replies;
@ -146,4 +146,3 @@ generate_pmsn_menu($pmsn_modul);
</div>
</div>
<?php

View File

@ -174,8 +174,9 @@ $post_count = 0; // Keep track of post numbers
$result = $db->query('SELECT id FROM '.$db->prefix.'pms_new_posts WHERE topic_id='.$tid.' ORDER BY id LIMIT '.$start_from.','.$pun_user['disp_posts']) or error('Unable to fetch pms_new_posts IDs', __FILE__, __LINE__, $db->error());
$post_ids = array();
for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
$post_ids[] = $cur_post_id;
while ($row = $db->fetch_row($result)) {
$post_ids[] = $row[0];
}
$post_view_new = array();

View File

@ -526,8 +526,9 @@ if (isset($_GET['tid']))
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id LIMIT '.$start_from.','.$pun_user['disp_posts']) or error('Unable to fetch post IDs', __FILE__, __LINE__, $db->error());
$post_ids = array();
for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
$post_ids[] = $cur_post_id;
while ($row = $db->fetch_row($result)) {
$post_ids[] = $row[0];
}
// Retrieve the posts (and their respective poster)
$result = $db->query('SELECT u.title, u.num_posts, g.g_id, g.g_user_title, p.id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE p.id IN ('.implode(',', $post_ids).') ORDER BY p.id', true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
@ -801,7 +802,7 @@ else if (isset($_POST['merge_topics']) || isset($_POST['merge_topics_comply']))
// Count number of replies in the topic
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$merge_to_tid) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
$num_replies = $db->result($result, 0) - 1;
$num_replies = $db->result($result) - 1;
// Get last_post, last_post_id and last_poster
$result = $db->query('SELECT posted, id, poster FROM '.$db->prefix.'posts WHERE topic_id='.$merge_to_tid.' ORDER BY id DESC LIMIT 1') or error('Unable to get last post info', __FILE__, __LINE__, $db->error());

View File

@ -138,8 +138,9 @@ while ($cur_group = $db->fetch_assoc($result))
$result = $db->query('SELECT u.id FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.', u.id ASC LIMIT '.$start_from.', 50') or error('Unable to fetch user IDs', __FILE__, __LINE__, $db->error());
$user_ids = array();
for ($i = 0;$cur_user_id = $db->result($result, $i);$i++)
$user_ids[] = $cur_user_id;
while ($row = $db->fetch_row($result)) {
$user_ids[] = $row[0];
}
if (!empty($user_ids))
{

View File

@ -186,8 +186,9 @@ if ($p == 1 && !empty($sf_array_tree[$id]))
$result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.$sort_by.', id DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']) or error('Unable to fetch topic IDs', __FILE__, __LINE__, $db->error());
$topic_ids = array();
for ($i = 0; $cur_topic_id = $db->result($result, $i); $i++)
$topic_ids[] = $cur_topic_id;
while ($row = $db->fetch_row($result)) {
$topic_ids[] = $row[0];
}
// If there are topics in this forum
if (!empty($topic_ids))

View File

@ -326,8 +326,9 @@ $post_count = 0; // Keep track of post numbers
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY id LIMIT '.$start_from.','.$pun_user['disp_posts']) or error('Unable to fetch post IDs', __FILE__, __LINE__, $db->error());
$post_ids = array();
for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
$post_ids[] = $cur_post_id;
while ($row = $db->fetch_row($result)) {
$post_ids[] = $row[0];
}
if (empty($post_ids))
error('The post table and topic table seem to be out of sync!', __FILE__, __LINE__);