PHP将多维数组插入mysql

时间:2011-10-21 08:26:00

标签: php mysql multidimensional-array

我尝试根据用户选择将预订摊位存储到数据库中,每个展位有10个复选框,用户可以选择他们想要预订展位的那一天。对于每个复选框在数据库中都有自己的字段,如果用户选择展位A01,D1和D2,当他按下保留按钮时,它会将值插入D1和D2。但我不知道如何将选中的复选框值存储在数据库中

我的展台界面 http://i.imgur.com/umYcI.gif

我的桌面结构 http://i.imgur.com/vKh6R.gif

我的编码

<?php
session_start();
if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) )  {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];

}
include('db.php');

if($_REQUEST){

$id     = $_REQUEST['search_category_id'];
$query2 = mysql_query("SELECT filenameBig, filename, url FROM eventinfo where eventID ='$id'");
  $row = mysql_fetch_array($query2, MYSQL_ASSOC);

if($id == -1)
{ 
  echo "<style type='text/css'>#btn_submit{visibility:hidden}</style>";
}

else{



      /*echo "<a href='{$row['url']}'>Click me!</a>";*/
      echo "<p><br><img src='{$row['filename']}' alt='' /></p>";
      echo "<p></p>";
      echo "<p align='right'><a href='$row[filenameBig]' target='_blank'>Click to view large image</a></p>";
      echo "<hr size='1'>";
      echo "<div style='padding-left:4px;' align='left'><strong>Booths Listing</strong>";
      echo "<p></p>";




$query = "select boothAlias, totalDay from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";

$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);


echo "<table border='0' style='width:400px;table-layout:fixed' >";


$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
 if($day==0){
    echo "<th>Booth</th>";
}else{
         echo "<th>D".$day."</th>";
    }
}

while($rows = mysql_fetch_array($result2)){
    $boothAlias=$rows['boothAlias'];
    $totalDay=$rows['totalDay'];


         echo "<tr><td>$boothAlias</td>";
             for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
                 echo "<td><input name='day2[]' type='checkbox' value='$day2' /></td>";
             }
        echo "</tr>";
}

echo "</table>";
}
}
?>

1 个答案:

答案 0 :(得分:0)

我认为SET类型对此很好。

http://dev.mysql.com/doc/refman/5.0/en/set.html