JustPaste.it

<?php
$server = 'localhost';
$username = 'id12087149_bpskotayogya';
$password = 'bpskotayogya';
$database = 'id12087149_bpskotayogya';

$con = mysqli_connect($server, $username, $password, $database);
if (mysqli_connect_errno()) {
echo "Failed to connect MySQL: " . mysqli_connect_error();
}

$query = mysqli_query($con, "SELECT * FROM infografik ORDER BY id_info ASC");

$json = '[';


// create looping dech array in fetch
while ($row = mysqli_fetch_array($query)){

// quotation marks (") are not allowed by the json string, we will replace it with the` character
// strip_tag serves to remove html tags on strings
$char ='"';

$json .=
'{
"id_info":"'.str_replace($char,'`',strip_tags($row['id_info'])).'",
"gambar_info":"'.str_replace($char,'`',strip_tags($row['gambar_info'])).'"
},';
}

// omitted commas at the end of the array
$json = substr($json,0,strlen($json)-1);

$json .= ']';

// print json
echo $json;

mysqli_close($con);
?>