我有一個查詢,它在我的貸款表中查找前10個最借貸的書籍,但是我想將這10個值存儲到一個數組中,以便我可以再次使用該數組。這裏是我到目前爲止的代碼...感謝您提前提供任何幫助!將字符串保存到數組
//select a database to work with
$selected = mysql_select_db("ds2",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT book.title, book.book_id, count(book.book_id) AS count_book_id, loan.book_id FROM book
INNER JOIN loan ON book.book_id = loan.book_id
GROUP BY book.book_id ASC
ORDER BY count(book.book_id) DESC");
$titles = array();
while($row = mysql_fetch_array($result))
{
echo $row['title'];
echo "<br>";
}
echo "<br><br>";
for($index = 1; $index <= 10; $index++)
{
array_push($titles,$result[$row]);
print_r($titles);
echo "<br>";
}
'$ titles [] = $ row ['title'];' –
問題在哪裏? – ficuscr
@RocketHazmat謝謝! – user1930227