我有工作得很好以下舊的PHP代碼:
<?php
$query = "SELECT * FROM notes WHERE note_name='Test Note'";
$result = mysql_query($query);
$note1 = mysql_result($result, 0, "note_content");
$note2 = mysql_result($result, 1, "note_content");
echo "<p>$note1</p>
<p>$note2</p>"
?>
我想將它轉化成mysqli的。我做了以下將它轉換,但它不工作:
<?php
$query = "SELECT * FROM notes WHERE note_name='Test Note'";
$result = mysqli_query($connect, $query);
// THIS IS WHERE I AM UNSURE WHAT TO DO??? HERE'S WHAT I TRIED
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$note1 = $row["note_content"][0];
$note2 = $row["note_content"][1];
echo "<p>$note1</p>
<p>$note2</p>"
?>
我在做什麼錯?如果沒有,你要取分開的每一行
$all_rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$note1 = $all_rows[0]["note_content"];
$note2 = $all_rows[1]["note_content"];
:
您在這裏失蹤的鏈接參數'$結果= mysqli_query($查詢);' –
@ShankarDamodaran我添加了鏈接參數,但這不是問題。 – user1822824
'不工作'不是很具體。 – 2014-02-22 03:15:58