How do I get the multivalued value of a column in a database?

Now I am trying to create a new code with a link from Swellar. but I do not know why. this code doesn't work at all. it will not show data. just show blank page

this code

<?php
$db = mysqli_connect("localhost","root","","silo");
$sQuery = "SELECT * FROM temp5";
$rResult = $db->query($sQuery);

$aResult = array();
while($aRow = mysqli_fetch_array($rResult)){
   $aResult[] = $aRow;
}

// explode each row and store in a new array
 $aResultArrays = array();
 foreach ($aResult as $row){           
     $aResultArrays[$row['no']] = explode(',',$row['nama']);
 }

      

I have a problem calling multiple data from a database column. I want to call this a separate value. enter image description here

in circle i. I want to call it on the table, but first I have to separate them. the table i want to create as

just an example:

|Nurudin |09-07-2017|;
|Nur Chotib| 09-07-2017|;
|Heri Prasetyo| 09-07-2017|;
|Moch Ali Imron| 09-07-2017;

      

Hopefully someone can give me some sample code for me.

+3


source to share


3 answers


Just try this:



$char='|';
foreach ($aResult as $row){           
     $aResultArrays[$row['no']] = $char.implode('|',explode(',',$row['nama'])).$char;
}

      

+2


source


Using explode () :



$names = explode(",",$retrievedNames);
foreach($names as $name)
{
    echo '|'.$name.'|'.$retrievedDate.'|';
}

      

+1


source


While the answers were given, this issue should not have occurred in the first place, since having multiple values ​​in one column is against database normalization , even 1NF.

Instead, create a new table for all your values ​​in "Nama" and another to map that table ID to the new one.

Example Here

0


source







All Articles