如何将数据传递给来自数组的会话,该数组也来自PHP中的数据库?

I have this problem. I am displaying all the animals which is owned by a certain pet owner. Here is my code:

<?php
session_start();
$_SESSION['indicator'] = "";
$conn = mysqli_connect("localhost","root","","appnimal") 
or die ("Could not connect to mysql because ".mysql_error());
$sql=mysqli_query($conn,"SELECT * FROM tbl_pet_animal WHERE pet_owner_id='$user'")
or die(mysql_error());
while($row=mysqli_fetch_array($sql))
{echo  "<tr class='even pointer record'>        
        <td class=' '>",$row[1],"</td>
        <td class=' '>",$row[2],"</td>
        <td class=' '>",$row[3],"</td>
        <td class=' '>",$row[4],"</td>
        <td class=' '>",$row[5],"</td>
        <td class=' '>",$row[6],"</td>
        <td class=' '>",$row[7],"</td>
        <td class=' '>",$row[8],"</td>
        <td class=' '>",$row[9],"</td>
        <td class=' '>",$row[10],"</td>
        <td><button type='button' 
                 onClick=location.href='try.php?".$_SESSION['indicator']."=$row[1]'>
       </td>";
 ?>

What am I trying to do is let us say, echo the $_SESSION['indicator'] value in another page. This is my code there from another page where I want to echo the value:

<?php
    session_start();
    $indicator="";
    $indicator= $_SESSION['indicator'];
    $conn = mysqli_connect("localhost","root","","appnimal") 
    or die ("Could not connect to mysql because ".mysql_error());
    $sql=mysqli_query($conn, "SELECT pet_animal_name FROM tbl_pet_animal WHERE pet_animal_name='$indicator'") or die(mysql_error());
    while($row=mysqli_fetch_array($sql)){
       echo ($row['pet_animal_name']);
    }
?>

But when I go there, it doesn't display anything. Please help me.

It displays nothing because (at least) in this code, your $_SESSION['indicator'] is "" (empty string) and You probably dont have pat with name "".

You can replace this part in first script :

<?php
session_start();
$_SESSION['indicator'] = "";
$conn = mysqli_connect("localhost","root","","appnimal") 

With

<?php
session_start();
$_SESSION['indicator'] = "ANY_NAME_FROM_DB"; // N.B.: strings can be case-sensitive.
$conn = mysqli_connect("localhost","root","","appnimal") 

And then check if you get something.

UPDATE #1 (from comments)

If you want to assign value on line

onClick=location.href='try.php?".$_SESSION['indicator']."=$row[1]'

You should do this instead:

onClick=location.href='try.php?".$_SESSION['indicator']=$row[1]."'

Because in your example "=$row[1]" is part of string, not php code. It means that .'=whatever' will not have any impact on value of your $_SESSION['indicator'].