我不知道如何在sql数据库中打印某个属性的标题,不知道为什么它向我输出了查询语句,我需要您的帮助。以下是我的php代码:
<?php
/* getting the last record */
$con=mysqli_connect("localhost","root","","task");
$t="SELECT * FROM note ORDER BY id DESC LIMIT 1";
$thetitle="SELECT title FROM note ORDER BY id DESC LIMIT 1";
if(mysqli_query($con, $thetitle)){
mysqli_query($con,$thetitle);
echo ("<button class='call_modal' style='cursor:pointer;'>$thetitle</button>");
}
?>
答案 0 :(得分:1)
希望对您有帮助
$query = "SELECT title FROM note ORDER BY id DESC LIMIT 1";
// Perform query
// For successful SELECT queries it will return a mysqli_result object
// For other successful queries it will return TRUE. FALSE on failure
$result = mysqli_query($con, $query);
// Fetch result row as an associative array:
// Note: Fieldnames returned from this function are case-sensitive.
$row = mysqli_fetch_assoc($result);
// Check if any result row was returned
if($row){
echo '<button class="call_modal" style="cursor:pointer;">'. $row['title'] . '</button>';
}
答案 1 :(得分:0)
请检查下面的代码
<?php
/* getting the last record */
$con = mysqli_connect("localhost","root","","task");
$t = "SELECT * FROM note ORDER BY id DESC LIMIT 1";
$thetitle = "SELECT title FROM note ORDER BY id DESC LIMIT 1";
if(mysqli_query($con, $thetitle)){
$result = mysqli_query($con,$thetitle); // run query and store the result in result variable
while ($row= mysqli_fetch_assoc($result)){ // fetch the result set
echo "<button class='call_modal' style='cursor:pointer;'>".$row['title']."</button>";
}
}
?>