我用核对箱表,从数据库中检索:
<?php
$result = mysql_query("SELECT shop_id, name FROM shop") or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_assoc($result))
{
echo <tr>
<td>
<input type="checkbox" name="identifer[]" value=" .$row[ shop_id ]. " /> <br />
</td>
<td> .ucfirst($row[ shop ]). </td>
</tr> ;
}
}
?>
我想节省数据库中的成果:
- Table:
places
- Columns:
places_id
,book_id
,shop_id
However, I can t get it to work right. In shop_id
column I get the same number as many times as checkboxes are checked.
如果是我这样说的话:
$identifer = $_POST[ identifer ];
if( count( $identifer) > 1)
{
foreach($identifer as $x)
{
$y .= $x.",";
$val = rtrim($y,",");
$q2 = "INSERT INTO places (places_id, book_id, shop_id) VALUES (NULL, $book_id , $val )";
$result2 = mysql_query($q2) or die(mysql_query());
}
}
在<条码>中,条码>表一只一行,不管检查箱的次数多。
So what is the correct way to do that?