PHP Mysql 递增外键
我如何手动增加外键。我有 2 张桌子
,
id-timeslot times
------------------
1 10:00
2 10:30
3 10:45
4 11:00
5 11:15
6 11:30
我有一段时间的表书
id-book id-timeslot
-------------------
1 1
2 1
下拉菜单(花费的分钟数)
<select name="minutes_booking" id="minutes_booking">
<option value="0">15 Minutes</option>
<option value="1">30 Minutes</option>
<option value="2">45 Minutes</option>
</select>
比方说,用户选择 10:00 和“治疗花费 30 分钟” 我想要看起来像
id-book id-times
-------------------
1 1
2 2
php 代码:
if($minutes_booking == 0) :
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('','" . $id_timeslot . "')" );
echo 'Booking has been added';
elseif($minutes_booking == 1) :
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('', '" . $id_timeslot . "')" );
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('', '" . $id_timeslot++ . "')" );
echo 'Booking has been added';
endif;
how do i manually increment foreign key. ive got 2 tables
table times
id-timeslot times
------------------
1 10:00
2 10:30
3 10:45
4 11:00
5 11:15
6 11:30
table book i have for a moment
id-book id-timeslot
-------------------
1 1
2 1
Dropdown menu (minutes to spend)
<select name="minutes_booking" id="minutes_booking">
<option value="0">15 Minutes</option>
<option value="1">30 Minutes</option>
<option value="2">45 Minutes</option>
</select>
lets say, the user select for 10:00 and "30 minutes to spend for the treatment"
i want look like
id-book id-times
-------------------
1 1
2 2
php code:
if($minutes_booking == 0) :
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('','" . $id_timeslot . "')" );
echo 'Booking has been added';
elseif($minutes_booking == 1) :
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('', '" . $id_timeslot . "')" );
$mysqli->query("INSERT INTO doc_a(id_book, id_timeslot)
VALUES ('', '" . $id_timeslot++ . "')" );
echo 'Booking has been added';
endif;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要将 id_book 字段切换为自动递增。您可以访问 phpMyAdmin 或某些工具来修改数据库表吗?那么你可能想使用更像这样的结构。它可能比这更好,但我试图让事情变得简单。
如果这对您有用,请选中该答案旁边的复选标记。谢谢!
First you need to switch the id_book field to auto increment. Do you have access to phpMyAdmin or some tool to modify the database tables? Then you may want to use a structure more like this. It could be better than this, but I am trying to keep things simple.
If this works for you, please select the check mark next to this answer. Thanks!
查看MySQL
UPDATE
语句 ,它允许您更改表中行中字段的值。Look at the MySQL
UPDATE
statement, which allows you to change the value of a field in a row in a table.