0
正在使用php Function
擺脫SQL 圖像URL,但我無法得到圖像的URL無法從函數獲取圖像URL
功能代碼來獲取圖像的URL
function getUsers() {//returns an array of users
global $db;
$list = array();
$stmt = $db->prepare('SELECT username FROM user_info');
$users = $stmt->fetch(PDO::FETCH_ASSOC);
if (is_array($users) || is_object($users)) {
foreach ($users as $user) {
array_push($list, $user[0]);
}return $list;
}
}
$users = getUsers();
function getImageURL($user) {
global $db;
$stmt = $db->prepare('SELECT propic FROM user_info WHERE username=:username');
$stmt->execute(array(':username' => $user));
$source = $stmt->fetch(PDO::FETCH_ASSOC);
return $source;
}
這裏是代碼顯示圖像
<?php
$user = $_GET['myUser'];
if (isset($_SESSION['username'])) {
$loggedIn = $_SESSION['username'];
}
$s = getImageURL($user);
foreach($s as $URL){
echo "<img class=\"full\" src=\"$URL[0] \" alt=\"$user's profile picture ERROR PART\"/>";
}
?>
什麼是輸出$ URL [0]? –
它應該是'$ URL ['propic']' – CodeGodie
其正確的s值=「s」我已附加圖片 –