Select 多行

Select multiple rows

如果字段的 id 等于 1,我想获取字段的所有成员。

数据库:

问题是,当我尝试获取所有照片目录时,我只得到第一个照片目录,而其他 2 个没有。

错误:

代码:

<?php

$yui1 = "SELECT photodirectory FROM photos WHERE photoowner='" . $userid . "'";
$rquery1 = mysqli_query($connDirectory, $yui1);
echo "rquery1 is equal to: "; 
var_dump($rquery1);
echo "</br>";

if($fotoutente = mysqli_fetch_row($rquery1)){ //fotoutente = userphoto

 for($c = 0; $c < count($fotoutente); $c++){
  echo '<img src="../' . $fotoutente["{$c}"] . '">' . "</br>";

    }
 
 echo "fotoutente is equal to: ";
 var_dump($fotoutente);
 
}
?>

如果 photodirectory 的 id 为 1,我如何获取所有成员? 无论如何,上面的 php 代码用于创建一个包含照片目录所有目录的数组,如果等等等等......

请救救我和加本大人打败playmysql4。 抱歉英语不好,但我是意大利人...

通过使用 while 循环迭代并在结果中使用 mysqli_fetch_assoc 来正确地重做代码。

这样做:

<?php

$yui1 = "SELECT photodirectory FROM photos WHERE photoowner= $userid ";
$result = mysqli_query($connDirectory, $yui1);
echo "rquery1 is equal to: ";
var_dump($result);
echo "</br>";

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo '<img src="../' . $row["photodirectory"] . '">' . "</br>";
    }
} else {
    echo "0 results";
}

?>

针对SQL注入:

<?php
if (ctype_digit(strval($userid)) === false) {
    echo "UserID is not valid!";
    exit();
}
$userid_secure = bin2hex($userid);
$rquery1 = mysqli_query($connDirectory, "SELECT photodirectory FROM photos WHERE photoowner=UNHEX('$userid_secure')";

if (mysqli_num_rows($rquery1) > 0) {
    while ($fotoutente = mysqli_fetch_assoc($rquery1)) {
        echo '<img src="../'.$fotoutente["photodirectory"].'"></br>';
    }
} else {
    echo "No results";
}
?>