Picking multiple fields from a column in mysql and splitting into arrays

Asked

Viewed 51 times

0

I have a mysql field called description, it stores arrays separated by '|'. forming a group.

When I have more than one group I add a * to the end to say that it is a new group.

2|Bags with gold finish |1|16,80|16.80 * 8|test bags 2 |3|9|27.00

I need to separate and show as follows:

2 Bags with gold finish 1 16,80 16,80 8 test Bags 3 9 27,00

So filling in these fields inserir a descrição da imagem aqui

If there are in the database 3.. 4..8 lines it must fill in these lines.

for example: 2 Bags with gold finish 1 16,80 16,80

<?php
foreach($oss_list as $cat_edit){
    $descricao= $cat_edit['descricao'];
    $campos = explode('|', $descricao);
    $array = [];
    
    //pega o total de linhas
    $totaldelinhas = substr_count($descricao, '*');
    $ir = 0;
    while ($ir < $totaldelinhas) {
        echo $tt = explode("|",$descricao);
?>
<tr>
    <td><input type="text" class="form-control cod" id="cod" name="cod[]" value=""></td>
    <td><input type="text" class="form-control desc" id="desc" name="desc[]"></td>
    <td><input type="text" class="form-control" id="qnd" name="qnd[]"></td>
    <td><input type="text" class="form-control" id="vlund" name="vlund[]" onblur="calcular()"></td>
    <!-- todos os inputs com style="display: none; são para uso nos calculos-->
    <td><input style="display: none;" type="text" class="form-control soma" id="vltotal" name="vltotal[]" onblur="calcular()">
        <input type="text" class="form-control somaS" id="vltotalS"></td>
</tr>
<?php
        $ir++;
    }
}
?>

8 test Bags 3 9 27,00 4 test Bags 4 4 7 23,00

how do I do that?

1 answer

0


Try it this way:

<?php 
    foreach($oss_list as $cat_edit){ 
        $descricao = explode('|', $cat_edit['descricao']);
?>
    <tr>
        <td><input type="text" class="form-control cod" id="cod" name="cod[]" value="<?php echo $descricao[0]; ?>"></td>
        <td><input type="text" class="form-control desc" id="desc" name="desc[]" value="<?php echo $descricao[1]; ?>"></td>
        <td><input type="text" class="form-control" id="qnd" name="qnd[]" value="<?php echo $descricao["2"]; ?>"></td>
        <td><input type="text" class="form-control" id="vlund" name="vlund[]" value="<?php echo $descricao[3]; ?>"></td>
        <!-- todos os inputs com style="display: none; são para uso nos calculos-->
        <td><input style="display: none;" type="text" class="form-control soma" id="vltotal" name="vltotal[]" onblur="calcular()">
            <input type="text" class="form-control somaS" id="vltotalS"></td>
    </tr>    
<?php } ?>
  • He created 3 input lines ( was 2 because I have two result groups and filled only the first one

  • @Richardbarcelos got it right?

  • Hello Friend, I changed the script, before registering everything in the bank in the same column I created a table for the description only.. then gave a foreach before the <tr> populating the fields. was beautiful, thanks for the support.

  • Perfect, if you can accept my answer... if it helped you, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.