gpt4 book ai didi

php - Mysql 连接并回显所有行,有条件

转载 作者:行者123 更新时间:2023-11-29 14:27:40 25 4
gpt4 key购买 nike

我需要连接两个表,我已经有了第一个表的代码:

$query = "SELECT * FROM civicrm_event"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['title_en_US']. " - ". $row['id'];
echo "<br />";

我需要将其与另一个名为 civicrm_participant 的项目加入,我需要在其中提取 contact_id

选择该表的子句是:

civicrm_event.id = civicrm_participant.event_id

然后我需要回显[title_en_US] [id] [contact_id]帮助...

最佳答案

You should read joins in mysql

做这样的事情:

$query = "SELECT ce.title_en_US, ce.id, cp.event_id FROM civicrm_event AS ce JOIN civicrm_participant AS cp ON ce.id=cp.event_id"; 

关于php - Mysql 连接并回显所有行,有条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10620999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com