I have the following code:
$query = "SELECT r.ResID, r.ResFirstName, AptFloor
FROM residents r JOIN apartments a ON r.AptID = a.AptID
WHERE ResFirstName = 'Richard'
AND AptFloor = 2
";
$result = mysqli_query($con, $query) or die('No residents fit your criteria');
while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$data[] = $row;
echo "ID: $row[ResID]<br>";
echo "Name: $row[ResFirstName]<br>";
echo "Floor: $row[AptFloor]<br>";
echo " NOW FROM ARRAY:<br>";
echo "#0 $data[0]<br>";
echo "#1 $data[1]<br>";
echo "#2 $data[2]<br>";
}
echo "<br><br>";
var_dump($data);
I want to be able to use the variables in other statements. I expected the “$data[0]”, etc. to hold those variables, but the output I get is as follows:
ID: 162
Name: Richard
Floor: 2
NOW FROM ARRAY:
#0 Array
#1
#2
ID: 426
Name: Richard
Floor: 2
NOW FROM ARRAY:This text will be hidden
#0 Array
#1 Array
#2
array(2) { [0]=> array(3) { [“ResID”]=> string(3) “162” [“ResFirstName”]=> string(7) “Richard” [“AptFloor”]=> string(1) “2” } [1]=> array(3) { [“ResID”]=> string(3) “426” [“ResFirstName”]=> string(7) “Richard” [“AptFloor”]=> string(1) “2” } }
How do I get the variables only - not the other things in the dump?