[英]fetch rows data with same values in two column
I tried this : this code : 我尝试了这个:此代码:
$sql="SELECT DISTINCT t_no,cust_name
FROM menu_order
WHERE b_id IN (
SELECT b_id,m_name
FROM menu_order
GROUP BY b_id
HAVING COUNT(*) > 1
)";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['t_no'];
echo $row['cust_name'];
while ($row = mysql_fetch_assoc($result, MYSQL_ASSOC)) {
$name = $row['m_name'];
$n = explode(',', $name);
foreach ($n as $d) {
if ($d !== '') { // because before first comma or after last can be empty
echo $d.",".PHP_EOL;
}
}
}
Please can any one tell how to fetch data with t_no(table number)
in common in php. 请问谁能告诉我们如何使用t_no(table number)
来获取数据。 Here, b_id(booking_id) is foreign key
. 在这里, b_id(booking_id) is foreign key
。
Expected Output is : 预期输出为 :
1 |T03 | 2017-08-07 | Dal Fry,Sahi Paneer,Aloo Paratha | 2,1,1
Here is the database: 这是数据库:
I think there is a problem in your query.. your sub query will return two columns including name, but the b_id IN()
would only require b_id. 我认为您的查询中存在问题。您的子查询将返回包括名称的两列,但b_id IN()
仅需要b_id。 Remove m_name
from your sub query. 从子查询中删除m_name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.