【问题标题】:How do I join two different tables? [closed]如何加入两个不同的表? [关闭]
【发布时间】:2017-07-30 11:32:01
【问题描述】:

我有两个表 customercustomer_pro,其中 customer 表具有自动递增的 customerID 和 customer_pro表的 cus_billId 也是自动递增的。

两个表都有不同的字段,例如 customer = customerID,name,amount,updAmount customer_pro= cus_billID,customerID,month,year.... p>

我想根据当前的 cus_billID 打印来自 customer_pro 的所有信息,以及根据客户表中的 amountupdAmount 已选择 客户 ID

我使用什么命令来获得想要的结果?

customer_pro的Html表单输入样例

Select customerID ........(**All **customerID** from customer Table)
Select Month      ........
select Year       ........

提交

当用户按下 submit 按钮时,所有信息将插入到 customer_pro 表中 并根据自动递增的当前 cus_billID 显示这些信息,并根据客户表显示 amountupdAmount 选定的 html 表单 customerID

【问题讨论】:

  • 编辑您的问题并提供示例数据和所需结果。然后添加一个使用关键字JOIN 的示例查询。你可能会做对的。
  • 欢迎来到 SO。请访问help center 了解询问内容和方式。提示:发布工作和代码

标签: php html mysql


【解决方案1】:

INNER JOIN 用于连接具有主键和外键的两个表 您的查询类似于:$sql = "SELECT * FROM customer_pro INNER JOIN customer ON customer_pro.customerID = customer.customerID"; 然后你将不得不使用

执行 sql 查询
$result = mysqli_query($dbconn, $sql;)

然后创建一个表并使用

while(mysqli_fetch_array($result))
{
your table fields here
}

【讨论】:

  • 您需要将该行存储在一个变量中:while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { // .... }。 (MYSQLI_ASSOC 是将列作为关联数组获取)。
  • 但是显示所有 customer_pro 信息我想打印当前 cus_billID 信息以及客户表 amountupdAmount 中的 2 个字段
  • @Md.AbuZaman - 以上是一个例子。调整它以满足您的需求。 (比如加入正确的表并添加WHERE 子句等。
  • 我正在使用 mySql
  • @Md.AbuZaman - 你应该使用 mysqli 或 pdo。 mysql_*-functions 是不安全的,已经被弃用了好几年,并在 PHP7.0 中完全删除
猜你喜欢
  • 2013-03-01
  • 2015-06-28
  • 2021-05-26
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多