Lesson Code: http://www.developphp.com/video/JavaScript/JSON-Timed-Ajax-PHP-MySQL-Data-Request-Web-Application Part 7 of learning JSON for beginners with Adam. In this final lesson of the series…
Original source
json tutorial for beginners part 7 Ajax PHP MySQL Data Request Programming
Tags
beginners, content, database, div, Dynamic, for, Gallery, header(), how, JSON, learn, mongodb, mysql, mysql tutorial, pa..., php, program, random, timed, to, tutorial, type
Share :
- tweet
-
About the : d4mer
sistema biblioteca php Mysql(CODIGO FUENTE GRATIS)
April 12th, 2019Apache, PHP & MySql on Docker
April 11th, 2019Python Flask and Vue Tutorial – Video 1
April 11th, 2019Importing MySQL Database
April 11th, 2019sistema escolar php y mysql Codigo Fuente Gratis
April 10th, 2019Connecting to MySQL database on Wampserver from any host (Computer)
April 10th, 201933 Comments
Leave A Comment
You must be logged in to post a comment.
Blu Strikes
HI, which "json" file did you use for this particular tutorial? Sorry, I must have missed it. I did follow all your other JSON tutorials previous and post, but never saw the JSON file used for this particular tutorial. Trying to use my gallery JSON file and nothing is working. I've had much success till now with all your other tutorials I have followed. Can you help me with this one. Thanks.
kogei bett
whats with the bot voice smdh
EduKSA
Please note that the SQL code in here is depreciated and will not work with new php. You can find equivalent code by googling php sql and finding the code there.
Aditya Gadi
plz tell whats wrong in this im not getting the output…its just show redirecting
json_mysql_data.php
<?php
header("Content-Type: application/json");
if(isset($_POST['limit'])){
$limit = preg_replace('#[^0-9]#', '', $_POST['limit']);
require_once("db_conx.php");
$i = 0;
$jsonData = '{';
$sqlString = "SELECT * FROM users ORDER BY RAND() LIMIT $limit";
$query = mysqli_query($db_conx,$sqlString) or die (mysql_error());
while ($row = mysql_fetch_array($query)) {
$i++;
$id = $row["id"];
$name = $row["name"];
$pass = $row["pass"];
$jsonData .= '"person'.$i.'":{"id":"'.$id.'","name":"'.$name.'", "pass":"'.$pass.'" },';
}
$jsonData = chop($jsonData, ",");
//$now = getdate();
//$timestamp = $now[0];
//$jsonData .= '"arbitrary":{"itemcount":'.$i.', "returntime":"'.$timestamp.'"}';
$jsonData .= '}';
echo $jsonData;
}
?>
html file
<html>
<head>
<style>
div#databox {
padding:12px;
background: #F3F3F3;
border:#CCC 1px solid;
width:550px;
height:310px;
}
</style>
<script>
var myTimer;
function ajax_json_data(){
var databox = document.getElementById("databox");
var arbitrarybox = document.getElementById("arbitrarybox");
var hr = new XMLHttpRequest();
hr.open("POST", "json_mysql_data.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var d = JSON.parse(hr.responseText);
arbitrarybox.innerHTML = d.arbitrary.returntime;
databox.innerHTML = "";
for(var o in d){
if(d[o].name){
databox.innerHTML += +d[o].id;
databox.innerHTML +=+d[o].name;
databox.innerHTML += +d[o].pass;
}
}
}
}
hr.send("limit=4");
databox.innerHTML = "requesting…";
//myTimer = setTimeout('ajax_json_data()',6000);
}
</script>
</head>
<body>
<h2>Timed JSON Data Request Random Items Script</h2>
<div id="databox"></div>
<div id="arbitrarybox"></div>
<script>ajax_json_data();</script>
</body>
</html>
Rob Baartwijk
Nice, but where is connect_db.php?
Chad Pace
Pronounced "jason" like the name bro
Nambi Jagannathan
great lessons..explained very well.
ALAMAT PH
Very useful tutorial.. Thank you. This really helps me working on my thesis.
44mod
Great job Adam you are the Poo!
Peter Floyd
Excellent tutorial. Worked after the first time (well I missed one bracket due to a typing error). Very straight forward!
M K
How tables for this example should look like (tables names ect)? help
MonadicBind
Not working for me. Help! … php doesn't go pass … if (isset($_POST['limit']))
A Estrada
just what I needed, thanks dude
Dominic Küchler
Hi Adam, found your tutorial series on my search for ressources for JSON to get started doing some stuff with android apps and getting data from mysql for this.
The videos are very well done, spoken slowly and good understandable (special when not native english speaking), giving the needed information to each used function at right time and an overview of the co-working of each function with the other.
They gave me a very good basic overview how to get started with JSON, thank you very much for the time you spend in this videos. Will keep an eye on your websites! Br Dom
TheRoxas13th
Hmm, what preg_replace do then? ._. I kinda confuse at there.
Noah Nobody
You can call the data from mysql with php, then pass the array result into php's json_decode() function.
salim ali
Do you have any tutorial for getting data from mysql database and and display using json ????
Fathur Rochman
how to get this file doc (PDF)
teilujj
I owe you a massive thank you! Your tutorials saved me. Got 100% on my assignment thanks to you 🙂
dirtyweasel
suppose there are no numbers in the limit variable?
Ping Charlton Chen
Hi Adam,
I have a problem to view the page I have copied the source codes and put them into the live server to test, it shows nothing but the request… Not sure what else I need to do.I have just copied the part 3 tutorial source code from your youtube site. Any helps would be greatly appreciated!
Billa Raj
Thanks Adam, Nice video series, Now I have good knowledge on JSON from basic. Thanks once again for your Amazing and excellent videos..
Peacemaker2027
DON'T FORGET THE GODDAMN FANLOADER!!! good video series!
Virtous
Hey Adam thanks for the great videos… do you have any tutorials that explain websockets?
mywayjohnson
How can we show an IMAGE from our DATABASE by the side of each. images can be jpg,JPEG,gif, and all other common image formats
Josh Zoff
dude i gotta thank you, i knew nothing about web development two weeks ago, now i'm coding in html, css, php, javascript, using jquery and ajax… now json. cant wait till the new web intersect videos come out. send me a msg back if u wanna check what i did with the site so far
Nikolay Mollov
Adam, can you insert an affiliate component in the new project
123japanuser
Salute to you for settling the issue with JSON, Thanks
Ionel Lupu
please make some socket server programming tutorials (without html5's websockets)
Isaac Price
Great job mang! This is really sweet.
MrShawnlloyd
haha, I saw your shortbus images on your desktop… too funny mang
Jay Mee
GREAT video your a genius can you help me build a buy friend (user) as a pet game called pets (similar to tagged dot com pets game where each user has a value and can be owned by other users. i have a few files but got stuck at how the user is displayed i can add a user that plays pets into the pets database and then got stuck on the link that a user can click to purchase / own a user on the pets game.
Adam Khoury
Don't use Ajax requests for that. I would not request or check database at intervals less than 10 seconds using Ajax. Look into socket server programming for that. PHP and JavaScript both are capable of socket server engineering. HTML5 also has websockets. Node.js and socketio are Frameworks for socket server programming.