Zin Myo Swe
Zin Myo Swe

Reputation: 938

how to read data that is stored with array in php and mysql

i stored data by using multiple checkbox in mysql. i want to show this stored data without include comma by using array. but, it is shown as the array was count comma

index.php


    include('config.php');
    $results = array();
    $sql = "select * from assign1 where id='1'";

    $run = mysqli_query($mysqli,$sql);


      while($row = mysqli_fetch_assoc($run)) {
        $results[] = $row['assign'];   ?> 

<p><?php print_r($results) ?></p>

<?php echo $results[0][0] ."".$results[0][2]."". $results[0][4] ?>

    <?php   } ?>

In mysql,

enter image description here

In output, i stored no 11, but array is only show 1.

output : 691

Upvotes: 0

Views: 77

Answers (2)

Swetha Sekar
Swetha Sekar

Reputation: 237

Use explode() to convert from string to array

$a = "1,2,3";
$d = explode(',',$a);
print_r($d);

Upvotes: 1

Amit Senjaliya
Amit Senjaliya

Reputation: 2945

Can you try to explode() function:

$results[] = explode(',', $row['assign']);

foreach($results as $result) {
    echo $result.'/n';
}

Upvotes: 1

Related Questions