Postingan lainnya
Error mysql_fetch_array() expects parameter 1 to be resourc
Ada yang tau cara mengatasi error seperti ini? Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp3\htdocs\portalBerita\berita.php on line 9 {"berita": ]}
Koding asli:
Terimakasih sebelumnya
1 Jawaban:
coba tambahin ini gan: <pre> <?php include 'config/koneksi.php'; $tampilkan = "SELECT * FROM tb_berita ORDER BY id_berita desc"; if($tampilkan=== FALSE) { die(mysql_error()); } $json = '{"berita": ['; $query_tampilkan = mysql_query($tampilkan);
if($query_tampilkan === FALSE) { die(mysql_error()); // TODO: better error handling }
while($row = mysql_fetch_array ($query_tampilkan)) { $char = '"'; $json .= '{"id":"'.$row['id_berita'].'", "judul":"'.str_replace($char,'`4',strip_tags($row['judul'])).'", "gambar":"http://127.0.0.1/portalBerita/foto_berita/'.$row['gambar'].' "},'; } $json = substr($json,0,strlen($json)-1); $json .= ']}'; echo $json; ?> </pre>