我可以调用我想在网站上显示的所有信息,但实际上我只需要显示某些数据,例如仅项目ID为1的事物。
我尝试了一些while函数。
//creating connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, user_id, project_id, hours FROM hours_worked";
$result = $conn->query($sql);
答案 0 :(得分:1)
只需将您的sql查询更改为:
$sql = "SELECT id, user_id, project_id, hours FROM hours_worked WHERE project_id ='".$project_id."';
根据需要更改WHERE子句。 如果只想显示与特定用户关联的记录,则将WHERE子句更改为:
WHERE user_id = *ENTER USER ID HERE*