Php 我怎样才能阻止这个循环?
我试图在一个字段中回显一次数据。然而,它是循环的,我不知道要改变什么才能让它回显一次。有人知道怎么做吗?代码如下:Php 我怎样才能阻止这个循环?,php,mysqli,Php,Mysqli,我试图在一个字段中回显一次数据。然而,它是循环的,我不知道要改变什么才能让它回显一次。有人知道怎么做吗?代码如下: <?php $email = $_POST['email']; $servername = "localhost"; $username = "root"; $password = ""; $dbName = "users"; //Make Connection $conn = new mysqli($servername, $username, $password,
<?php
$email = $_POST['email'];
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "users";
//Make Connection
$conn = new mysqli($servername, $username, $password, $dbName);
//Check Connection
if(!$conn){
die("Connection Failed. ". mysqli_connect_error());
}
$sql = "SELECT `profilepicurl` FROM users WHERE `email`='".$email."'";
$result = mysqli_query($conn ,$sql);
if(mysqli_num_rows($result) > 0){
//show data for each row
while($row = mysqli_fetch_assoc($result)){
echo $row['profilepicurl'];
}
}
?>
谢谢 这很简单
将while($row=mysqli\u fetch\u assoc($result)){
更改为$row=mysqli\u fetch\u assoc($result){
删除while()
循环和大括号:
if ( mysqli_num_rows($result) > 0 ) {
//show data for each row
$row = mysqli_fetch_assoc($result);
echo $row['profilepicurl'];
}
停止循环的正确方法是使用: 尽管如此,如果您只需要1值,您可以删除
while
循环并仅使用:
$row = mysqli_fetch_assoc($result);
echo $row['profilepicurl'];
注意事项:
由于sql注入的可能性,您的脚本不安全。请务必阅读。在
$row['profilepicurl']之后添加break;
;
您使用的是while循环!如果不想循环,为什么要使用它?说明了解的语句。甚至是不安全的!
$row = mysqli_fetch_assoc($result);
echo $row['profilepicurl'];