html 连续发送数据库,不要在循环中对数据库进行操作.htm
不要在循環中對數據庫進行操作
性能非常低下,應改為用IN查詢
示例:
1、在循環中查詢數據庫,增加gv_title屬性(性能低下)
foreach ($res['data'] as &$val)
{
$gamesql??? =?? 'SELECT `gv_title` FROM
`mzw_game_version` WHERE `gv_id` =
'.$val['gv_id'];
$gamequery? =?? $this->db->query( $gamesql
);
$val['gv_title']??????? =?? isset(
$gamequery->row()->gv_title ) ? $gamequery->row()->gv_title :
'';
$val['select_name_cf']????????? =
'';
$val['do_name_cf']?????????????
=
'';
$val['iTotalRecords']??????????
=
$res['total'];
$val['iTotalDisplayRecords']??? =
$res['total'];
$val['gc_client']??????????????
=
$arr_client[$val['gc_client']];
$val['gc_hide']????????????????
=
$arr_hide[$val['gc_is_hide']];
$val['gc_top']?????????????????
=
$arr_top[$val['gc_is_top']];
$val['gc_top_time']????????????
= date( 'Y-m-d H:i:s', $val['gc_top_time']
);
$val['gc_create_time']????????? =
date( 'Y-m-d H:i:s', $val['gc_create_time']
);
}
2、改用 IN 查詢,速度提高至少10倍
foreach ($res['data'] as &$val)
{
$vid[]?????????????????????????
= $val['gv_id'];
color=#ff0000>//將gv_id存入到數組
$val['select_name_cf']????????? =
'';
$val['do_name_cf']?????????????
=
'';
$val['iTotalRecords']??????????
=
$res['total'];
$val['iTotalDisplayRecords']??? =
$res['total'];
$val['gc_client']??????????????
=
$arr_client[$val['gc_client']];
$val['gc_hide']????????????????
=
$arr_hide[$val['gc_is_hide']];
$val['gc_top']?????????????????
=
$arr_top[$val['gc_is_top']];
$val['gc_top_time']????????????
= date( 'Y-m-d H:i:s', $val['gc_top_time']
);
$val['gc_create_time']????????? =
date( 'Y-m-d H:i:s', $val['gc_create_time']
);
}
if ( empty( $vid ) )??? $vid =
array(0);
$vid_str??? =?? implode( ',', $vid
);
$sql??????? =?? "SELECT
gv_title,gv_id FROM mzw_game_version WHERE gv_id IN ({$vid_str})";
color=#ff0000>//用IN方法對id數組進行查詢
$query????? =?? $this->db->query( $sql
);
$title_res? =??
$query->result_array();
$title_arr? =??
array();
foreach ($title_res as $k => $v)
{
$title_arr[$v['gv_id']] =??
$v['gv_title'];
}
foreach ($res['data'] as &$val)
{
$val['gv_title']??? =??
$title_arr[$val['gv_id']];
}
一鍵復制
編輯
Web IDE
原始數據
按行查看
歷史
總結
以上是生活随笔為你收集整理的html 连续发送数据库,不要在循环中对数据库进行操作.htm的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html函数中怎么写超链接,如何调用ht
- 下一篇: html编译软件推荐,3款容易上手的HT