我有这段代码,我用它来打印数据库中的一些字段。
我的问题是我收到有关提供的 foreach 无效参数和 mysql 获取数组问题的错误。
代码是这样的:
foreach( $checked1 as $key => $value){
echo "<th> $value </th>";
}
echo "</tr></thead>";
while($row = mysql_fetch_array($result)){
$checked1
数组在哪里
$checked1 = $_POST['checkbox'];
这里有什么问题?
整个代码:
<?php
echo "<div id='table-3'>";
if(isset($_POST['Submit'])) {
echo "<pre>";
$checked1 = $_POST['checkbox'];
$checked = implode(',', $_POST['checkbox']);
}
$con = mysql_connect('localhost','user','passwd');
mysql_query("SET NAMES UTF8");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$result = mysql_query("SELECT $checked FROM hostess");
echo "<table >";
echo "<thead><tr>";
if(is_array($_POST['checkbox'])){
foreach( $checked1 as $key => $value){
echo "<th> $value </th>";
}
echo "</tr></thead>";
} else {
echo "Checkbox is not an array.";
}
while($row = mysql_fetch_array($result)){
echo "<tr>";
foreach($checked1 as $key => $value){
if($value == 'photo'){
echo "<td> <img src=foto/photo1/".$row[$value] . "></td>";
} else if($value == 'photo2'){
echo "<td><img src=foto/photo2/".$row[$value] . "></td></td>";
}
else if( $value == 'photo2' && $value == 'photo'){
echo "<td> <img src=foto/photo1/".$row[$value] . "></td>";
echo "<td><img src=foto/photo2/".$row[$value] . "></td></td>";
}
else{
echo "<td>" . $row[$value] . "</td>";
}
}echo "</tr>";
}
echo "</table>";