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 codelist($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?

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.