Sinisterly
Using AJAX? - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Design (https://sinister.ly/Forum-Design)
+--- Forum: Web Design (https://sinister.ly/Forum-Web-Design)
+--- Thread: Using AJAX? (/Thread-Using-AJAX)

Pages: 1 2


Using AJAX? - troy_odyssey34 - 04-18-2014

How do I make ajax return multiple rows from a mysql table. So far my query works but I can only get it to return one row.

What I have right now is this for my PHP:
Code:
<?php session_start(); mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db("quackbook") or die(mysql_error()); if(isset($_SESSION["user"]) === FALSE){ header("location: index.php"); } $find = "SELECT Firstname,Post FROM wall LEFT JOIN info ON info.Username=wall.Username"; $arrow = mysql_query($find); $array = array(); $i = 0; $j=0; while($fire = mysql_fetch_array($arrow)){ $array[$i] = $fire; $i+1; } echo json_encode($array[$i]); ?> And this is my JS: var post,dispost; var ready; window.onload=function(){ hunt(); setInterval(change,500); }; function change(){ dispost.innerHTML= post; }; function hunt(){ xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","Classes/class.wall.php",true); xmlhttp.send(); xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ ready= JSON.parse(xmlhttp.responseText); begin(); } }; }; function begin(){ post=ready["Firstname"]+" posted: "+ready["Post"]+"<br><br>"; dispost=document.getElementById("dispost"); };



Using AJAX? - troy_odyssey34 - 04-18-2014

How do I make ajax return multiple rows from a mysql table. So far my query works but I can only get it to return one row.

What I have right now is this for my PHP:
Code:
<?php session_start(); mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db("quackbook") or die(mysql_error()); if(isset($_SESSION["user"]) === FALSE){ header("location: index.php"); } $find = "SELECT Firstname,Post FROM wall LEFT JOIN info ON info.Username=wall.Username"; $arrow = mysql_query($find); $array = array(); $i = 0; $j=0; while($fire = mysql_fetch_array($arrow)){ $array[$i] = $fire; $i+1; } echo json_encode($array[$i]); ?> And this is my JS: var post,dispost; var ready; window.onload=function(){ hunt(); setInterval(change,500); }; function change(){ dispost.innerHTML= post; }; function hunt(){ xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","Classes/class.wall.php",true); xmlhttp.send(); xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ ready= JSON.parse(xmlhttp.responseText); begin(); } }; }; function begin(){ post=ready["Firstname"]+" posted: "+ready["Post"]+"<br><br>"; dispost=document.getElementById("dispost"); };



Using AJAX? - troy_odyssey34 - 04-18-2014

How do I make ajax return multiple rows from a mysql table. So far my query works but I can only get it to return one row.

What I have right now is this for my PHP:
Code:
<?php session_start(); mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db("quackbook") or die(mysql_error()); if(isset($_SESSION["user"]) === FALSE){ header("location: index.php"); } $find = "SELECT Firstname,Post FROM wall LEFT JOIN info ON info.Username=wall.Username"; $arrow = mysql_query($find); $array = array(); $i = 0; $j=0; while($fire = mysql_fetch_array($arrow)){ $array[$i] = $fire; $i+1; } echo json_encode($array[$i]); ?> And this is my JS: var post,dispost; var ready; window.onload=function(){ hunt(); setInterval(change,500); }; function change(){ dispost.innerHTML= post; }; function hunt(){ xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","Classes/class.wall.php",true); xmlhttp.send(); xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ ready= JSON.parse(xmlhttp.responseText); begin(); } }; }; function begin(){ post=ready["Firstname"]+" posted: "+ready["Post"]+"<br><br>"; dispost=document.getElementById("dispost"); };



RE: Using AJAX? - Ex094 - 04-18-2014

This might help you http://stackoverflow.com/questions/9614044/return-all-records-from-table-with-ajax


RE: Using AJAX? - Ex094 - 04-18-2014

This might help you http://stackoverflow.com/questions/9614044/return-all-records-from-table-with-ajax


RE: Using AJAX? - Ex094 - 04-18-2014

This might help you http://stackoverflow.com/questions/9614044/return-all-records-from-table-with-ajax


RE: Using AJAX? - zomgwtfbbq - 04-18-2014

It's better to post your code. If we can't check how you handle the data that was transferred it's just guessing. Did you use firebug to check what data is returned?


RE: Using AJAX? - zomgwtfbbq - 04-18-2014

It's better to post your code. If we can't check how you handle the data that was transferred it's just guessing. Did you use firebug to check what data is returned?


RE: Using AJAX? - zomgwtfbbq - 04-18-2014

It's better to post your code. If we can't check how you handle the data that was transferred it's just guessing. Did you use firebug to check what data is returned?


RE: Using AJAX? - troy_odyssey34 - 04-20-2014

Here is the code:

Code:
<?php session_start(); mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db("quackbook") or die(mysql_error()); if(isset($_SESSION["user"]) === FALSE){ header("location: index.php"); } $find = "SELECT Firstname,Post FROM wall LEFT JOIN info ON info.Username=wall.Username"; $arrow = mysql_query($find); $array = array(); $i = 0; $j=0; while($fire = mysql_fetch_array($arrow)){ $array[$i] = $fire; $i+1; } echo json_encode($array[$i]); ?>