我试着从两个表中提取数据

$query2 = mysql_query("SELECT * FROM supplier_stats, supplier_registration WHERE supplier_stats.company_reg_number = supplier_registration.company_reg_number AND supplier_stats.insurance_date = DATE(NOW())");
        while($row = mysql_fetch_array( $query2 )) {
        echo "<div class=\"contact_details\">Supplier Contact Details:<br/>";
        echo "<p>".$row['contact_name']."</p></div>";

        echo "<div class=\"contact_details\">Supplier Contact Details:<br/>";
        echo "<p>".$row['contact_email']."</p></div>";

        } ?>

我要做的是从一个表中获取insurance_date和表supplier_stats中的联系人详细信息,并按两个表中的supplier_registration对其进行分组,但这不会产生任何影响,我也不会出错。

最佳答案

试试这个,

$query2 = mysql_query(" SELECT supplier_registration.contact_name,
                               supplier_registration.contact_email
                        FROM supplier_registration
                        INNER JOIN supplier_stats
                        ON supplier_registration.company_reg_number = supplier_stats.company_reg_number
                        WHERE supplier_stats.insurance_date = DATE(NOW())");

关于php - 从x和x匹配的2个表中提取结果?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23538389/

10-11 17:22