有没有办法获取值的匹配主键?
我试过这些:
$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";
}
?>