douzhe1264 2014-02-26 00:12
浏览 47
已采纳

mysql_query选择限制在525结果

I have a select and is limited at 525 results otherwise the while will stuck.

    $query_other = "SELECT * FROM prod where active=1 and aprobat=1";
    $other = mysql_query($query_other, $conn) or die(mysql_error());
    while($row = mysql_fetch_assoc($other)){
        $other_prod[]=$row;
    } 

In cpanel it shows more than 525 and when i did var_dump on $other its says resource(525) of type (mysql result). Its on Apache Server if that helps.

If i put LIMIT 525 it works and show all page otherwise is just blank page. Anything after the while doesn't work.

P.S : I know mysql_ is deprecated i hate it but is required at the task and i have no power over it.

  • 写回答

2条回答 默认 最新

  • dongqixuan3112 2014-02-26 00:19
    关注

    Increasing memory won't help. It's just a temporary fix. Plus you need to think of multiple clients doing the same query at the same time. How's the system going to keep up with the memory consumption.

    BUT be selective about the fields you need to pull back.

    Don't:

    SELECT *
    

    Do:

    SELECT `field1`, `field2`, ...
    

    This will decrease memory consumption and let you deal with things. I imagine you don't need all the rows. And you especially want to avoid TEXT/BLOB ones as they are usually large. Select them only when you need to display/use them.

    You can also use:

    LIMIT 0, 100
    

    to paginate through the results. Might help you a bit but I'd select the right fields to fix this permanently.

    Also set:

    ini_set('display_errors', true);
    error_reporting(-1);
    

    and see if PHP tells you more about what goes wrong.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大