Forum Moderators: open
foreach($_POST as $key => $value){
if (is_array($value)) {
echo "$key = ";
foreach ($value as $a) {
echo "<i>$a, </i>";
}
echo "<br>";
}else{
echo "$key = $value<br>";
}
}
Is there a way to do this same thing with mysql query results? I have it hard coded right now using:
$query = ("SELECT * FROM `table`)");
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print mysql_field_name($result, 0) . ": " . $row[ID]."<br>";
print mysql_field_name($result, 1) . ": " . $row[name]."<br>";
print mysql_field_name($result, 2) . ": " . $row[address]."<br>";
print mysql_field_name($result, 3) . ": " . $row[city]."<br>";
etc. but I'd like to be able to do it using a loop if possible and I just can't come up with one that will work. Can anyone help?
$rows = mysql_query("SELECT * FROM table");
$list = '';
$count = 0;
$ri = false; // Reverse Image (alternate row shading)
while ($row = mysql_fetch_assoc($rows)) {
// Column Headings:
if (++$count == 1) {
$list .= '<tr class="ri">';
foreach($row as $key => $value) {
$list .= '<td>'.htmlentities($key)."</td>\n";
}
$list .= "</tr>\n";
}
$list .= '<tr' . (($ri) ? ' class="ri"' : '') . '>';
foreach($row as $value) {
$list .= '<td>'.htmlentities($value)."</td>\n";
}
$list .= "</tr>\n";
$ri = !$ri;
}