donglvmang8638 2017-02-28 09:45
浏览 32

list()函数和mysqli_fetch_array一起工作吗?

i have created a php code with some help in which i fetched out all similar arrays in my mysql table using while loop... the code is`

<?php
    include("connection.php");

    global $con;


    $sql1= "SELECT name FROM vi_books ORDER BY views DESC";


    $query1= mysqli_query($con,$sql1);

 while ($row = mysqli_fetch_assoc($query1)) {

   $new_row=htmlspecialchars($row['name']);

    echo "<br>";
echo $new_row;   
}
?>

`

Now i wanted to manipulate the result array using list function so that i can echo only some specific results. Supposedly, i want to run the following code list($s1,$s2)=$new_row; echo $s1."and".$s2;

But on running this nothing is showing(like empty values are been passed in my list function variables). Plzz help me out. I guess i need AJAX or JS to manipulate the array result as i want to. Is that true?

  • 写回答

1条回答 默认 最新

  • dongshan4518 2017-02-28 09:56
    关注

    You have 2 problems here, depending on where you use list():

    1. $new_row is a string and not an array in your code, so using list() with that variable does not make any sense.
    2. According to the manual, list() only works on numerical arrays and assumes the numerical indices start at 0 and you are getting an associative array with mysqli_fetch_assoc(). You'd need to switch to mysqli_fetch_array() or use array_values() on the result to be able to use list().

    By the way, using an array is almost always more convenient than setting multiple variables.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看