0

我试图弄清楚如何获得要发布的返回值。我的代码如下

    <?php

$mysqli = new mysqli("localhost","user","password","db");

$lname=$_POST['lname'];


$query= "SELECT * FROM contacts WHERE lname = '".$lname."'";
$result = $mysqli->query($query);     
if (!$result) {
  printf("Query failed: %s\n", $mysqli->error);
  exit;
}      

return $result;
?>

我对 php 很陌生,但是我正在做的是获取一个发布到 php 文件的名称,然后它进入数据库,找到所有输入了姓氏的值,然后我希望它返回这些值,然后打印它们

4

1 回答 1

0

mysqli_result::fetch_assoc

<?php

$mysqli = new mysqli("localhost","user","password","db");

$lname=$_POST['lname'];


$query= "SELECT * FROM contacts WHERE lname = '".$lname."'";
$result = $mysqli->query($query);     
if (!$result) {
  printf("Query failed: %s\n", $mysqli->error);
  exit;
}      
while ($contact = $result->fetch_assoc()) {
    echo $contact['name']."<br>\n";
}
?>
于 2012-06-01T15:36:04.243 回答