-3
I am creating a dynamic table using PHP.
The problem and the following created a field to modify the values of the variable $conteudo
table body however can’t change more than one table field someone there can help me to solve this problem?
PS. to pass the field to be modified and as follows (field 1,field 2,field 3)
<?php
/*
* CABEÇALHO DA TABELA
*/
$campos = explode(',','id,nome,idade,sexo');
$conteudo = explode(',','1,funano,21,1');
/*
* MODIFICADOR DE CAMPOS
*/
$modificador = explode(',','21');
echo '<table border="1px" width="100%">';
echo '<tr>';
foreach($campos as $x){
echo '<th>'.$x.'</th>';
}
echo '</tr>';
/**
* CONTEUDO DA TABELA
*/
echo '<tr>';
foreach($conteudo as $b){
/*
* COMPARANDO O MODIFICADOR COM O CAMPO DA TABELA
*/
foreach($modificador as $m) {
if ($b == $m) {
echo '<th>' . 'campo' . '</th>';
} else {
echo '<td>'.$b.'</td>';
}
}
}
echo '</tr>';
echo '</table>';
The problem happens when I try to add another field to modify as for example:
$modificador = explode(',','21,funano');
explains more what you tried ... from what I see in the comments who did knows well what has there
– Otto
runs the script you will understand better
– Alexandre Sousa
explains better what you need and what you tried to make clear
– Otto
You can only change one field because it only uses one field in the modifier, it works right here: http://phpfiddle.org/main/code/n7ri-zas8
– Jorge B.
Jorge B tries to add another field $modifier = explodes(',','21,so-and-so'); and see what will happen to the table
– Alexandre Sousa
Then you compare "21" from
$m
with "21" of$b
and when this happens it replaces "21" with "field".– Jorge B.
perfect now to scold and try to compare more than one table field when I try that the table gets all bugged
– Alexandre Sousa
This is because you always print either field or value whenever you compare.
– Jorge B.
And how to solve this jam?
– Alexandre Sousa
Let’s go continue this discussão in chat.
– Alexandre Sousa