this is my first question here, sorry for my bad english, the for loop result show "Done! 6000 rows affected." when the table have 6,235 rows, what is wrong?.
<?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;
?>
the result must be "Done! 6235 rows affected!". is first time using for loops with limit querys.
regards.
EDIT:
i use the folowing way:
$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
}
and now show me Done! 6235 rows affected, is correct that way?.
It's just a display problem, your query retrieve the 6235 rows because you display the "from limit" and not the "how many i retrieve"
If we do your loop step by step (we imagine it's until 1235, it's shorter)
$limit = 500;
$output = '';
//maybe there are better solutions for this
for ($i=0;$i<=$totalMembers;$i+=$limit)
{
// query here
$output = 'Done! ' . $i . ' rows affected.';
}
If your problem is "I don't retrieve all data", you don't have a problem
If your problem is the display, add to $i
the count of rows from mysqli_query
( http://www.w3schools.com/php/func_mysqli_num_rows.asp )
So the result is $ouput = "Done! ".($i + mysqli_num_rows($get_members))." row affected"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.