我的數據庫包含表user
- >字段 - >username
,userid
擷取結果從MySQL查詢PHP數組
$user = (" SELECT userid,username FROM user ");
while ($row = @mysql_fetch_assoc($user))
{
$getalluser[] = $row;
}
我試圖讓數組的結果是這樣的:
$users = array(
0=>array(
"Mark",
"http://localhost/test/image.php?u=1",
"Mark"
),
1=>array(
"Anandu",
"http://localhost/test/image.php?u=2",
"anandu"
),
2=>array(
"jeena",
"http://localhost/test/image.php?u=3",
"jeena"
)
);
注意:
Mark,Anandu,jeena
- > username AND u=1,u=2,u=3
- > userid
定義網址,以便您不要重複自己:'$ URL = 'HTTP://localhost/test/image.php U =?';'。然後,在循環中:'$ getalluser [] = array($ row ['username'],$ url。$ row ['userid']);'(我沒有包含用戶兩次因爲我看不到需要它) – FirstOne
請[停止使用mysql_ *函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。該擴展在PHP 5.5.0中被棄用,並且在PHP 7.0.0中被刪除。相反,[MySQLi](http://php.net/manual/en/book.mysqli.php)或[PDO_MySQL](http://php.net/manual/en/ref.pdo-mysql.php)應該使用擴展名。另請參見[MySQL:選擇API](http://php.net/manual/en/mysqlinfo.api.choosing.php)指南和[相關FAQ](http://php.net/manual/en/faq .databases.php#faq.databases.mysql.deprecated)以獲取更多信息。 – FirstOne
@FirstOne,謝謝兄弟..我會嘗試你的代碼 –