Extract exploded results from a column

1

I inserted several data within the same column with implode , now I want to extract the results of the query with the explode in order to get the data separated and then to work.

I have the code this way, but it is not returning anything in the arrays:

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');

$sql = "SELECT arrachar FROM centrodb.marcacaoInfancia";

$result = mysqli_query($conn, $sql);

    $result1 = explode(' ', $result);

    echo $result1[0];
    echo $result1[1];
    echo $result1[2];
    echo $result1[3];
    echo $result1[4];
    echo $result1[5];
    echo $result1[6];
    echo $result1[7];
    echo $result1[8];
    echo $result1[9];
    echo $result1[10];
    echo $result1[11];
    
asked by anonymous 24.04.2018 / 12:33

2 answers

3

You have to "treat" this $result to determine how you want to manipulate the data.

A widely used method is fetch_assoc() that returns an associative array of the table.

So let's loop with fetch_assoc() and read each row of the table:

while ($linha= mysqli_fetch_assoc($result)) {
    $result1 = explode(' ', $linha["arrachar"]);
    var_dump($result1);
}

If you only have one row or one query with limit 1 you can ignore while .

$linha= mysqli_fetch_assoc($result);
$result1 = explode(' ', $linha["arrachar");
var_dump($result1);

Another example making use of fetch_array (common array, numeric)

$linha= mysqli_fetch_array($result, MYSQLI_NUM);
$result1 = explode(' ', $linha[0]);
var_dump($result1);
    
24.04.2018 / 12:45
0

Try something like this:

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');

$sql = "SELECT arrachar FROM centrodb.marcacaoInfancia";

$result = mysqli_query($conn, $sql);
$data = '';

while($row = $result->fetch_assoc()) {
    $data .= $row["arrachar"].',';
}
$result1 = explode(',', $data);

echo $result1[0];
echo $result1[1];
echo $result1[2];
echo $result1[3];
echo $result1[4];
echo $result1[5];
echo $result1[6];
echo $result1[7];
echo $result1[8];
echo $result1[9];
echo $result1[10];
echo $result1[11];
    
24.04.2018 / 13:21