我是PHP的初学者我试图生成PDF但我在如何显示所选复选框中的数据方面遇到了麻烦。例如,我想使用此select * from table where id in ($stk)
选择两行或三行或四行,但它显示为空白。
<input type='checkbox' name='stick[]' id="stick" value =' <?php echo $row['id']; ?>' />
$name = isset($_POST['stick'])?$_POST['stick']:NULL;
if(isset($_POST['stick'])){
foreach ($name as $stk){
$query = "SELECT * FROM machine_and_equipments where MENo in($stk)";
$result = mysql_query($query) or die (mysql_error());
while($query_row = mysql_fetch_assoc($result)){
$controlnumber = $query_row['MENo'];
$assetname = $query_row['machine_equipments_name'];
$location = $query_row['Location'];
$text = sprintf("%s\n%s\n%s\n%s\n%s", "Koushin Mechatronics Manufacturing Philippines Inc. ", ' PROPERTY STICKER', 'Control No. : '. $controlnumber .' ', 'Asset Name : '. $assetname .' ', 'Location : '. $location .' ');}
答案 0 :(得分:0)
你有一个非常好的基础,但是有一个小错误,你正在循环你的SQL调用。你应该在哪里为你的IN($ stk)做一个逗号分隔列表。
看一下这个答案:How to convert items in array to a comma separated string in PHP?
所以
foreach ($name as $stk){
应该是
$stk = implode(',', $name);
并记得删除最后一个&#34;}&#34;因为你不再需要了