我不太明白为什么,但我的代码生成了表中每个数据库行的2个。
这是我的选择语句

//select all data
$query = "SELECT e.employeeid, e.name, e.title, e.phone, s.name as supplier_name, e.created
            FROM employeestest e
                LEFT JOIN supplierstest s
                    ON s.supplierid
            ORDER BY e.employeeid DESC
            LIMIT :from_record_num, :records_per_page";

$stmt = $con->prepare($query);
$stmt->bindParam(":from_record_num", $from_record_num, PDO::PARAM_INT);
$stmt->bindParam(":records_per_page", $records_per_page, PDO::PARAM_INT);
$stmt->execute();

//number of rows returned
$num = $stmt->rowCount();

这就是我填充表的地方(前面有标题,这就是为什么没有开始表标记)
// retrieve table contents
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

    extract($row);

    //creating new table row per record
    echo "<tr>";
        echo "<td class='text-align-center'><input type='checkbox' name='item[]' class='checkboxes' value='{$employeeid}' /></td>";
        echo "<td>{$name}</td>";
        echo "<td>{$title}</td>";
        echo "<td>{$phone}</td>";
        echo "<td>{$supplier_name}</td>";
        echo "<td>{$created}</td>";
        echo "<td>";

            // update record
            echo "<a href='update_product.php?employeeid={$employeeid}' class='btn btn-info margin-right-1em'>";
                echo "<span class='glyphicon glyphicon-edit'></span> Rediger";
            echo "</a>";

            // delete record
            echo "<a delete-employeeid='{$employeeid}' delete-file='delete_product.php' class='btn btn-danger delete-object'>";
                echo "<span class='glyphicon glyphicon-remove'></span> Slet";
            echo "</a>";

        echo "</td>";
    echo "</tr>";
}
//end table<br>
echo "</table>";

如果需要更多代码,请告诉我!

最佳答案

你的情况不对。你需要一个条件。像这样的:

        FROM employeestest e LEFT JOIN
             supplierstest s
             ON s.supplierid = e.supplierid
-----------------------------^

或者是链接两个表的适当列。

09-27 17:24