mysql - Fill data in html php table from POST -
i want fill data in table. values sessions , post.
there method getting values want put in table.
if ( isset($_post) ) { //$valuee[] = array(); foreach ( $_post $key => $value ) //$valuee[] = str_split($value, 3); var_dump($value); //extract($valuee); { $cr = explode( "&",$key ); // ◄■■ split : [0]="corp_resp",[1]="1". } mysqli_query( $con,"insert respostas (menuid,corp_resp,id,data, id_avaliacao) " . "values ('{$cr[1]}','$value', '{$cr[2]}', '{$cr[5]}', '{$cr[3]}')" ); }
that output want put in table var_dump($value)
.
string(4) "0.00" string(4) "0.00" string(4) "0.45" string(4) "0.00" string(4) "0.00" string(4) "0.50" string(4) "0.65" string(4) "0.75" string(4) "0.00" string(4) "0.00" string(4) "0.00" string(4) "0.60" string(4) "0.65" string(4) "0.00" string(4) "0.00" string(4) "0.60"
there code building table. table dynamic according select before post. code need handle number of columns , lines.
$s2 = $_session['categorias']; $utilizador = $_session['utilizador']; $ucount = $_session['cparametro']; $carcount = $_session['ncategoria']; $table ="<center><table><tr><center><td>parametro</td></center>"; for($x = 0; $x < $carcount; $x++){ $val= htmlspecialchars($s2[$x], ent_html5 | ent_compat, 'utf-8'); $table= $table."<td>".$val."</td>"; } $table = $table."</tr>"; for($i = 0 ; $i <$ucount ; $i++ ){ $table = $table."<tr><td>".$utilizador[$i]."</td>"; for($j=0;$j<$carcount;$j++){ $val= htmlspecialchars($s2[$j], ent_html5 | ent_compat, 'utf-8'); $table = $table."<td>"; $table = $table.$value; $table = $table."</td>"; } } $table = $table."</tr>"; $teste = "resultado"; $table= $table."<center><td>$teste</td></center>"; $table = $table."</table>"; echo $table;
where $table = $table.$value;
need pass values correct before in fills , not passing last one? rest of table correct.
like see in picture output:
before post:
after post:
new output:
this seems awfully complicated, results in not being able identify problem, in short; problem using:
$table = $table.$value;
but $value not correct variable, should use:
$table = $table.$val;
longer idea: if improve code use notation:
$table.= "append var"
instead of:
$table = $table . "append var"
it makes lot more readable, think simplify more..
why have $carcount , $s2?
i think $carcount tell how many categories in $s2, use count($s2) instead, reduce amount of code, $ucount , $utilizador
this same, , starts more readable, i'm sure can simlified more, in few minutes:
$s2 = $_session['categorias']; $utilizador = $_session['utilizador']; $table ="<table><tr><center><td>parametro</td>"; foreach($s2 $cat){ $val= htmlspecialchars($s2[$cat], ent_html5 | ent_compat, 'utf-8'); $table.= "<td>".$val."</td>"; } $table .= "</tr>"; foreach($utilizador $util){ $table.= "<tr><td>".$util."</td>"; foreach($s2 $cat){ $val= htmlspecialchars($cat), ent_html5 | ent_compat, 'utf-8'); $table.="<td>$val</td>"; } } $table.= "</tr>"; $table.= "<td>resultado</td>"; $table.="</table>"; echo $table;
it nicer if put in function, , call function need table.
Comments
Post a Comment