我不知道这是否可能,但似乎应该是......
对于每个语句,我都有一个在 php 上运行的 javascript 弹出框。该应用程序是一种座位表。数据库表中有 50 张宴会桌,每张有 10 个座位和一个桌号。
我查询数据库并询问表活动字段设置为“是”的所有字段。然后对于每个表,我想显示一个弹出表单,以便用户可以为每个座位输入一个名称。问题是这样的。当我打开表单的第一个实例时,它显示表 id 为 1。当我打开表单的第二个实例时,我希望它显示表 id 2 - 但它显示表 id 1。我如何获取表单的每个实例显示“下一个”表?
这是我正在使用的代码:
global $wpdb;
$seatings = $wpdb->get_results("SELECT * FROM bb_cl_seating WHERE table_active='yes' ");
if (count($seatings)===0){
echo "<h2>There are no tables - Would you like to add one?</a>";
} else {
foreach($seatings as $seating){
?>
<!-- link that opens popup -->
<a class="popup-with-form" href="#table-form" onclick="jQuery('#table-form-<?php echo $seating->table_id; ?>').show(); return false;">Open form</a><br />
<!-- form itself -->
<form method="post" id="table-form-<?php echo $seating->table_id; ?>" class="white-popup-block mfp-hide">
<h1>Celebrity Luncheon Seating</h1>
<fieldset style="border:0;">
<ol>
<li>
Table Number: <?php echo $seating->table_id; ?>
</li>
<li>
<label for="seat_one">Seat One</label>
<input name="seat_one" type="text" id="seat_one" value="<?php echo $seating->seat_one; ?>" size="50" />
</li>
<li>
<label for="seat_two">Seat Two</label>
<input name="seat_two" type="text" id="seat_two" value="<?php echo $seating->seat_two; ?>" size="50" />
</li>
<li>
<label for="seat_three">Seat Three</label>
<input name="seat_three" type="text" id="seat_three" value="<?php echo $seating->seat_three; ?>" size="50" />
</li>
<li>
<label for="seat_four">Seat Four</label>
<input name="seat_four" type="text" id="seat_four" value="<?php echo $seating->seat_four; ?>" size="50" />
</li>
<li>
<label for="seat_five">Seat Five</label>
<input name="seat_five" type="text" id="seat_five" value="<?php echo $seating->seat_five; ?>" size="50" />
</li>
<li>
<input name='table_id' type='hidden' id='table_id' value='<?php echo $seating->table_id; ?>' /><input name='table_active' type='hidden' id='table_active' value='<?php echo $seating->table_active; ?>' /><input name="update" type="submit" id="Submit" value="update" />
</ol>
</fieldset>
</form>
<?php } // closes for each ?>
<script type="text/javascript">
jQuery(document).ready(function( $ ) {
$('.popup-with-form').magnificPopup({
type: 'inline',
preloader: false,
focus: '#seat_one',
// When elemened is focused, some mobile browsers in some cases zoom in
// It looks not nice, so we disable it:
callbacks: {
beforeOpen: function() {
if($(window).width() < 700) {
this.st.focus = false;
} else {
this.st.focus = '#name';
}
}
}
});
});
</script>