drrw8672 2017-02-08 17:48
浏览 30

几次搜索php,mySQL,Json后内存超载

I am having a problem of memory overload. I am using a code to make searches in a database that uploads different text boxes in a form. The first few searches are quick, but as I look for more terms, it becomes much slower and takes a lot of time. I need help with a code that can free up memory every time the function is performed.

These are the codes on the upload form:

Javascript code:

<script src="jquery-ui-1-12-1/jquery-3.1.1.min.js"></script>
<script src="jquery-ui-1-12-1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
    $("#nombre").autocomplete({
            source: "pedir_datos.php",
            minLength: 2,
            select: function(event, ui) {
                event.preventDefault();
                $('#nombre').val(ui.item.nombre);
                $('#grado').val(ui.item.grado);
                $('#id').val(ui.item.id);
             }

    });
});
</script>

HTML:

.<div class="ui-widget"> <input type="text" size="18"  id="nombre" name="nombre" autofocus="autofocus" placeholder="Buscar" class="sugerencias"></div>

Search page (request_data.php):

PHP code:

$busqueda = $_GET['term'];
if ($busqueda != ""){
    # conectare la base de datos
    $con=@mysqli_connect("localhost", "root", "1234", "escuela");
    $return_arr = array();
    /* Si la conexión a la base de datos , ejecuta instrucción SQL. */
    if ($con){
        $fetch = mysqli_query($con,"SELECT * FROM alumnado where nombre like '%".$busqueda."%' ORDER BY id"); 
/* Recuperar y almacenar en conjunto los resultados de la consulta.*/
        while ($row = mysqli_fetch_array($fetch)) {
            $row_array['value'] = $row['nombre']." | ".$row['grado'];
            $row_array['id']=$row['id'];
            $row_array['nombre']=$row['nombre'];
            $row_array['grado']=$row['grado'];
            array_push($return_arr,$row_array);
        }
    }
}
/* Cierra la conexión. */
mysqli_close($con);
/* Codifica el resultado del array en JSON. */
echo json_encode($return_arr);

Thank you!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图