Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

php - 我对如何从另一个表中获取列有问题(i have a problem with how to get a column frrom another table)

This is my table and data of each table

(这是我的表和每个表的数据)

Table reservation :

(餐桌reservation :)

+------------------+---------  +---------+
| rid              | r_date    | r_time  |
+------------------+---------  +---------+
| 1                | 2019-12-20| 10:00:00| 
| 2                | 2019-12-20| 10:00:00|
| 3                | 2019-12-20| 10:00:00|
+------------------+-----------+---------+

Table combo :

(表combo :)

+------------------+---------------+------------+
| combo_id         | combo_name    | combo_price|
+------------------+---------------+------------+
|    1             | Package 1     | 250.00     | 
|    2             | Package 2     | 250.00     |
|    3             | Package 3     | 250.00     |
+------------------+---------------+------------+

I want to get the combo_name from combo table to reservation table and should look like this

(我想从组合表获取保留表的combo_name,应该看起来像这样)

+-------------+-----------+---------+------------+
|  rid        | r_date    | r_time  |combo_name  |
+-------------+-----------+---------+-----+------+
|   1         | 2019-12-20| 10:00:00| Package 1  |
|   2         | 2019-12-20| 10:00:00| Package 2  |
|   3         | 2019-12-20| 10:00:00| Package 3  |
+-------------+-----------+---------+-----+------+

this is my code pls help

(这是我的代码请帮助)

$query = mysqli_query($con, "select * 
                             from reservation 
                             where  r_status='Approved' 
                               and r_date>='$today' 
                             order by r_date"
         ) or die(mysqli_error($con))`;
  ask by joesantriani translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use join query :

(您可以使用联接查询:)

$query = mysqli_query($con, "SELECT res.*, com.combo_name FROM reservation res join combo  com on res.rid = com.combo_id where  r_status='Approved' and r_date>='$today' ORDER BY  r_date"
         ) or die(mysqli_error($con))`;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...