如何在php中获取值的匹配主键?

时间:2016-09-04 10:37:49

标签: php mysqli primary-key

有没有办法获取值的匹配主键?

我试过这些:

$user_id = $mysqli->insert_id($username);
$user_id = $mysqli->primary_key($username);

但它没有用。例如,在下面的echo中,我想显示John Grisham的user_id,这是另一个表中的外键。然后是与John Grisham或列出相关的类别。

    <?php

$username = "John Grisham";
//$user_id = $mysqli->insert_id($username);
//$user_id = $mysqli->primary_key($username);

require_once('dbConnect.php');

$resultSet = $mysqli->query("SELECT cat_name FROM category WHERE category.user_id = $user_id");

while($rows = $resultSet->fetch_assoc())

    {
        $user_id = $rows['cat_name'];

        echo "<p>categories are $user_id";

    }
    ?>

0 个答案:

没有答案