www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Ajax Using PHP to pull in database records

  1. #1
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56

    resolved [RESOLVED] Ajax Using PHP to pull in database records

    Hi eveyone,

    I'm trying to use ajax to pull records from a database and display them one at a time with a 10 second pause between each record. The following function pulls all of them and displays them at once every 10 seconds.

    Code:
    function getCat(str) {
    	if (window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	  }
    	else
    	  {// code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	xmlhttp.onreadystatechange=function() 
    	  {
    	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		document.getElementById("details").innerHTML=xmlhttp.responseText;
    		
    		}
    	  }
    	xmlhttp.open("GET","changeCat.php?x="+str,true);
    	xmlhttp.send();
    	setTimeout("getCat('yes')",10000);
    }
    I'm thinking I need to pull the use PHP to pull the results from the database and store them in an array. Then use JS to iterate through the array. If so, I'm not sure how to do that. Each record has 15 fields. If I'm on the wrong track please let me know what track i should be on. I appreciate any help.

    Thanks,

    Tim

  2. #2
    Join Date
    Nov 2010
    Posts
    1,085
    so, this line:

    Code:
    document.getElementById("details").innerHTML=xmlhttp.responseText;
    shows all 15 of the records at once, but you would rather split them and put them in an array?

    If so, it is hard to say how without seeing the responseText object you can put this line below that one:
    Code:
    console.log(document.getElementById("details").innerHTML=xmlhttp.responseText);
    and view the object in Chrome's javascript console. Or provide a link to the page where this is happening.

  3. #3
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56
    Thanks for the reply. here is the link

    http://www.westbywi.com/test.php

  4. #4
    Join Date
    Nov 2010
    Posts
    1,085
    where are the 15 fields? Is it that every house (or whatever they are) has 15 pieces of information ('cos I count 12 or so).

    Better yet: what do you want your array to look like?

  5. #5
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56
    I found a way to do it. I had php write the js. then i could call the records with a js function.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles