Sto provando a restituire quattro record dal mio database MySQL ma viene restituito solo il primo record. Ho cercato ma non sono sicuro del motivo. Qualcuno può indicarmi la giusta direzione?Perché viene restituito solo il primo record da questo array PHP?
<?php
session_start();
function displayImage($username){
$imageDate = $_POST['imageDate'];
$result = mysql_query("
SELECT
imageName
FROM
images AS i
INNER JOIN
users AS u ON i.userID = u.UserID
WHERE
u.username = '$username'
AND
i.imageDate = '$imageDate'
") or die(mysql_error());
//return a message to the users explaining ......
if (!isset($_POST['Submit'])) {
// this does nowt yet!!!
$output = "Nothing selected yet.";
}
else {
//This is a while loop to store the SQL results into ......
$row = array(mysql_fetch_assoc($result));
foreach ($row as $picName) {
$cam = $_POST['cam'];
$fullPath = $username . "/" . $cam . "/" . $picName['imageName'];
// $output = //this works fine
reset($images);
}
}
var_dump($row);
echo "<br />";
return $output;
}
?>
"// Questo è un ciclo while per memorizzare i risultati SQL in ......" - No, non lo è. Vuoi qualcosa come 'while ($ row = mysql_fetch_assoc ($ result) {...}' ma mentre ci sei, per favore considera di passare al PDO. – hank
Hai una vulnerabilità di SQL injection qui, tra l'altro - è necessario – halfer