gpt4 book ai didi

php - 在 'for' 循环中显示的总行数与查询 PHP + MYSQL 不同

转载 作者:行者123 更新时间:2023-11-29 12:04:34 25 4
gpt4 key购买 nike

这是我的第一个问题,抱歉我的英语不好,for 循环结果显示“完成!6000 行受影响。”当表有 6,235 行时,出了什么问题?

<?php
//get the total rows of Members table.
$count_members = mysqli_query($ipb_connection,'SELECT * FROM ' . $from_prefix. 'members');
$totalMembers = mysqli_num_rows($count_members);

mysqli_free_result($count_members);

//start convertion
$limit = 500;
$output = '';
//maybe there are better solutions for this
for ($i=0;$i<=$totalMembers;$i+=$limit)
{
$get_members = mysqli_query($ipb_connection,'
SELECT
m.member_id AS id_member, SUBSTRING(m.name, 1, 80) AS member_name,
m.joined AS date_registered, m.posts,
m.member_group_id AS id_group,
m.last_visit AS last_login, SUBSTRING(m.name, 1, 255) AS real_name,
IFNULL(m.msg_count_total, 0) AS instant_messages,
SUBSTRING(m.conv_password, 1, 64) AS passwd,
SUBSTRING(m.email, 1, 255) AS email_address,
STR_TO_DATE(IF (m.bday_year = 0 AND m.bday_month != 0 AND m.bday_day != 0, CONCAT("0004-", m.bday_month, '-', m.bday_day), CONCAT_WS('-', IF(m.bday_year <= 4, 1, m.bday_year), IF(m.bday_month = 0, 1, m.bday_month), IF(m.bday_day = 0, 1, m.bday_day))), "%Y-%m-%d") AS birthdate,
s.cache_content as signature,
"" AS lngfile, "" AS buddy_list,
"" AS pm_ignore_list, "" AS message_labels, "" AS personal_text,
"" AS time_format, "" AS usertitle, "" AS member_ip, "" AS secret_question,
"" AS secret_answer, "" AS validation_code, "" AS additional_groups,
"" AS smiley_set, "" AS password_salt,
pf.field_2 AS msn, pf.field_3 AS website_url, pf.field_6 AS location,
pf.field_1 AS aim, pf.field_4 AS icq, pf.field_8 AS yim,
IF(pf.field_5 = "m" AND pf.field_5 != "u",1,2) AS gender
FROM {string:prefix}members m
LEFT JOIN foro_content_cache_sigs s on m.member_id = s.cache_content_id
LEFT JOIN foro_pfields_content pf on m.member_id = pf.member_id
WHERE m.member_id != 0
LIMIT ' . $i .', ' . $limit);

$output = 'Done! ' . $i . ' rows affected.';
}

echo $output;
?>

结果必须是“完成!6235 行受影响!”。第一次使用带有限制查询的 for 循环。

问候。

编辑:

我使用以下方式:

$limit = 100;
$parts = $totalMembers / $limit;
$output = '';
$affected = 0;
//maybe there are better solutions for this
for ($i=0;$i<=$totalMembers;$i+=$limit * $parts)
{
//query here
}

现在告诉我完成了! 6235 行受到影响,这样正确吗?

最佳答案

这只是一个显示问题,您的查询检索 6235 行,因为您显示“来自限制”而不是“我检索了多少行”

如果我们一步步执行你的循环(我们假设直到 1235,它会更短)

$limit = 500;
$output = '';
//maybe there are better solutions for this
for ($i=0;$i<=$totalMembers;$i+=$limit)
{
// query here
$output = 'Done! ' . $i . ' rows affected.';
}
  • 第一个循环: $i = 0 到 500,ouput =“完成!0 行受影响”
  • 第二个循环: $i = 500 到 1000,ouput =“完成!500 行受影响”
  • 第三次循环: $i = 1000 到 1235,ouput =“完成!1000 行受影响”

如果您的问题是“我没有检索到所有数据”,那么您就没有问题

如果您的问题是显示,请将 mysqli_query 中的行数添加到 $i ( http://www.w3schools.com/php/func_mysqli_num_rows.asp )

所以结果是$ouput = "Done! ".($i + mysqli_num_rows($get_members))."row受影响"

关于php - 在 'for' 循环中显示的总行数与查询 PHP + MYSQL 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31765570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com