473,586 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Get Mysql Data with Ajax ?!

abdoelmasry
104 New Member
Hi Prof's

im new in ajax

i need some help

i wanna create active web page linked to mysql database

i mean .. i open my page , it will automatically view database contents

it will also get any changes in databse

like if any row deleted or any row created

i will make javascript timer to call function that get mysql data every 1 second

my last mean ... How to get Mysql Data With Ajax ???

i need some ideas

Thanks
May 15 '08 #1
4 2386
acoder
16,027 Recognized Expert Moderator MVP
First, get your server-side script working which connects to the MySQL database and outputs the data.

Once you have that working, it's simply a case of calling the script using Ajax. See an example.
May 15 '08 #2
abdoelmasry
104 New Member
Thank U acoder

I got it
May 19 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You're welcome.

Can you post your working code here for the benefit of others? Thanks.
May 19 '08 #4
abdoelmasry
104 New Member
Here is my code :

Javascript code:

Expand|Select|Wrap|Line Numbers
  1. function createajaxrequest(){
  2. var req;
  3. if(window.XMLHttpRequest){
  4. req = new XMLHttpRequest();
  5. } else if(window.ActiveXObject) {
  6. req = new ActiveXObject("Microsoft.XMLHTTP");
  7. } else {
  8. alert('Error Creating Ajax Request');
  9. exit;
  10. }
  11. return req;
  12. }
  13.  
  14. function getphotoslist(){
  15. var serverpage="getphotos.php?action=refreshphotos";
  16. xmlhttp = createajaxrequest();
  17. xmlhttp.open("get",serverpage);
  18. xmlhttp.onreadystatechange = function() {
  19. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  20. photosdiv.innerHTML = xmlhttp.responseText;
  21. }
  22. }
  23. xmlhttp.send(null);
  24. getphotosloop = setTimeout("getphotoslist()",2000);
  25. }
Html Page:

[HTML]<html>
<head>
<title> </title>
</head>
<body>
<div id="photosdiv"> </div>
</body>
</html>[/HTML]

getphotos.php Code :
[PHP]<?php

if($_GET["action"]=="refreshphoto s"){

function getphotoslist() {
$gtdata=mysql_q uery("select id,name,path,ti me,date,postby, pcip from photos");
while($cdata=my sql_ftch_row($g tdata)){
$photoinfo[$cdata[0]]=array("id"=>"$ cdata[0]","name"=>"$cda ta[1]","path"=>"$cda ta[2]","time"=>"$cda ta[3]","date"=>"$cda ta[4]","postby"=>"$c data[5]","pcip"=>"$cda ta[6]");
}
return $photoinfo;
}

function getphotoscode($ photosarray){
while(list($key ,$value)=each($ photosarray)){
$itemcode="id->$photosarray[$key][id] :: name->$photosarray[$key][name] :: path->$photosarray[$key][path] :: time->$photosarray[$key][time] :: date->$photosarray[$key][date] :: postby->$photosarray[$key][postedby] :: pcip->$photosarray[$key][pcip]";
$listcode.="<br >.$itemcode";
}
return $listcode;
}

$phlist=getphot oslist();
$phlistcode=get photoscode($phl ist);
echo $phlistcode;
exit;
}
?>[/PHP]

Greeting
Jul 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3757
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I understand it I need a PHP script that pulls the query and dumps the data into XML format, that is called by triggering a javascript event that reads that...
3
1709
by: emrahayanoglu | last post by:
Hello Everyone, I have question about efficient usage of connecting to mysql. Now, i'm using 6 or 7 queries in a page with ajax. In Addition to that, i open connection to mysql for every query. I think it isn't efficient way. However, when i open only one connection to use for every query, php interpreter gives error. What should i do for...
4
3758
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was working fine until today. I am trying to implement some ajax with the javascript framework mootools (although I don't see how this is causing the problem...
1
3331
by: bcochofel | last post by:
Hi, I'm using Perl CGI and HTML::Template to generate the following XML: ---------------------------------------------------------------------- <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xml" href="RR.xsl"?> <!-- $Id: template.xml,v 1.5 2006/12/11 11:13:30 bcochofel Exp $ --> <RR...
6
9750
jafarsalam
by: jafarsalam | last post by:
hi; I'm new to PHP and AJAX MySQL codes. I found a simple code for PHP and AJAX MySQL Database communication on : http://www.w3schools.com/php/php_ajax_database.asp I downloaded the code and uploaded to my server but it does not work . I script does not display the data from the database. Can anyone look at this and help me out.
0
7354
by: tusaar | last post by:
Hi all I am in big need for a drop down menu created with php, mysql and ajax. Exactly, I need three drop down menu (Category, Subcategory and Item). The data of each drop down will come from Mysql. Anybody can help me please.. I will be very much thankfull. Please help me and give me a proper solution for that ASAP. Thanks Tushar
3
1954
by: jarremw | last post by:
hello all, what i have is a modal popup control extender, i have an ajax script that saves the value of the two textboxes that are in the popup, what i am needing is a way to insert those values into my mysql database using ajax since the server side code will have already been executed, how would i go about doing this, i have read on the...
1
4592
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the...
7
1818
angelhiso
by: angelhiso | last post by:
hei coild somebody help me with ajax mysql ? I use ajax to put data to my database but why i can not put the charector like ' \ ? for example i want to put the word DON'T which has the 'it could not do it why ? what should i do ?
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.