$data = [
'id' => $myrow_index[id],
'name' => $name,
'price' => $myrow_index[price]
];
echo json_encode($data);
$id = $_GET['id'];
$result_index = mysql_query("SELECT * FROM shop WHERE id=$id");
$myrow_index = mysql_fetch_array($result_index);
$name = $myrow_index[name];
$price = $myrow_index[price ];
echo $name;
echo $price;
$.ajax({
method: 'post',
url:'/test1/modul.php',
data: {"id":'1'},
dataType: "json",
success: function(data) {
alert(data);
},
});
<?php
$result_json = array();
$mysqli = new mysqli("***", "**", "**", "**");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT name, price FROM blog ORDER by ID DESC LIMIT 50";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
$result_json[] = $row["name"]." ".$row["price"];
}
$result->close();
}
$mysqli->close();
echo json_encode($result_json);
exit();
<?php
include("moduls/db.php");
$result_index = mysql_query("SELECT * FROM vibor WHERE idtovar=1");
$myrow_index = mysql_fetch_array($result_index);
$result = $myrow_index[price];
echo json_encode($result);