store mysqli_query result in session

前端 未结 3 1805
轮回少年
轮回少年 2021-01-24 13:10

I want to store the result of a MySQLi query as a session variable so that I can reuse it without executing the query again. I don\'t want to execute the same query on every pag

3条回答
  •  故里飘歌
    2021-01-24 14:02

    Try this:

      if(!isset($_SESSION['query_result'])){
         $anything=mysqli_query($connection,"select something from table name where filed1='$variable' order by id DESC limit 70");
         while($res = mysqli_fetch_row($anything)){
            array_push($_SESSION['query_result'], $res);
         }
      } else {
         $anything = $_SESSION['query_result'];
      }
    while($data=mysqli_fetch_array($anything)){
       print_r($data);
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题