Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Here is the code for pulling the data for my array

<?php

    $link = mysqli_connect('localhost', 'root', '', 'mutli_page_form');

   $query = "SELECT * FROM wills_children WHERE will=73";

  $result = mysqli_query($link, $query) or die(mysqli_error($link));

    if ($result = mysqli_query($link, $query)) {

  /* fetch associative array */

    if($row = mysqli_fetch_assoc($result)) {

        $data = unserialize($row['children']);

    }

   /* free result set */

    mysqli_free_result($result);

    }

?>

When I use print_r($data) it reads as:

Array ( [0] => Array ( [0] => Natural Chlid 1 [1] => Natural Chlid 2 [2] => Natural Chlid 3 ) ) 

I would like it to read as:

Natural Child 1

Natural Child 2

Natural Child 3

1 Answer

0 votes
by (40.7k points)

Use the code given below:

foreach($data[0] as $child) {

   echo $child . "\n";

}

in place of print_r($data)

Related questions

0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 30, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...