Udtræk til multidimentionel-array
Jeg har oprettet en funktion ,som skal udtrække data til et multidimentionel array.Jeg ønsker at anbringe oplysningerne i input-felter hvor længden af feltet svarer til længden i selve databasen.
Hvordan styrer jeg længden?
Min kode:
<?php
function array2table($arr,$width)
{
$count = count($arr);
if($count > 0){
reset($arr);
$num = count(current($arr));
echo "<table align=\"center\" border=\"1\"cellpadding=\"5\" cellspacing=\"0\" width=\"$width\">\n";
echo "<tr>\n";
foreach(current($arr) as $key => $value){
echo "<th>";
echo $key." ";
echo "</th>\n";
}
echo "</tr>\n";
while ($curr_row = current($arr)) {
echo "<tr>\n";
$col = 1;
while (false !== ($curr_field = current($curr_row))) {
echo "<td>";
?>
<input type=text name="areal" size=30 value="<?php echo $curr_field ?>"
<?php
echo "</td>\n";
next($curr_row);
$col++;
}
while($col <= $num){
echo "<td> </td>\n";
$col++;
}
echo "</tr>\n";
next($arr);
}
echo "</table>\n";
}
}
include("../conn.php");
// Add DB connection script here
$query = "SELECT navn, email, telefon FROM $bestyrelse";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$array[] = $row; }
array2table($array,600); // Will output a table of 600px width
?>