-4

MySQL でエラーが発生しました。これは私のスクリプトです:

<?php
include 'koneksi.php';
$data="SELECT * FROM `article` WHERE 1";
$result = mysql_query($data);
while ($row = mysql_fetch_array($result)) {
$judul1= $row['judul'];
$isi1=$row['isi'];
echo "<h2 align='center'> $judul1 </h2>";
echo "<p class='padding'>$isi1</p><hr>";
};
?>

結果: 警告: mysql_fetch_array() は、パラメーター 1 がリソースであると想定しており、24 行目の C:\xampp\htdocs\cms\index.php で指定されたブール値です。

24行目: while ($row = mysql_fetch_array($result)) {

このエラーを修正するにはどうすればよいですか?

ありがとう

4

2 に答える 2

0

次のように修正できます。

index.php

<?php
include 'koneksi.php';
$data="SELECT * FROM `article` WHERE 1";
$result = mysql_query($data);

if($result === FALSE) {
    die(mysql_error()); // TODO: better error handling
}

while ($row = mysql_fetch_array($result)) 
{
$judul1= $row['judul'];
$isi1=$row['isi'];
echo "<h2 align='center'> $judul1 </h2>";
echo "<p class='padding'>$isi1</p><hr>";
};
?>

koneksi.php

<?php
 mysql_connect('localhost','root','');
 mysql_select_db('project');
?>
于 2013-08-03T07:36:34.267 に答える