How to show an array with several values stored in the same field

0

I have a field that stores a value of an array with several separate data with (,) in the same field of the database, as I do to show that data to show that information in a report.

$sql = mysqli_query($con, "select * from document where project_id in (".$project_id.
  ")");
while ($row = mysqli_fetch_array($sql)) {
  $array = explode(",", $row['project_id']);
  foreach($array as $projects) {
    echo $projects;
  }
}

Displays the following error:

Fatal error: Can not use object of type mysqli_result as array in C: \ wamp64 \ www \ SysCPC \ ajax \ documents.php on line 129

The information you should show is the Department

    
asked by Julián Cordoba 07.06.2018 в 23:31
source

1 answer

0

One more step is missing. The variable $ sql is an object with all the records returned by your query, you have to read each record in order to access the data like this:

$sql = mysqli_query($con, "select * from project where id in (" . $project_id . ")");
while($row = mysqli_fetch_assoc($sql)) {
  echo $row['id'];      
}
    
answered by 07.06.2018 в 23:34