We help IT Professionals succeed at work.
Get Started

Ajax, get information from database and show in the browser

Pedro Chagas
Pedro Chagas asked
Last Modified: 2012-05-12
Hi E's, my knowlgment in Ajax is very poor, usually I use HTML and php for made my websites.
Now I need to resolve a problem with Ajax, and maybe this step was my beginning in Ajax.
In snippet code I have a form, where I can put a number, and that number have a title correspondent in my database. If I write 1000 appear one title, if I write 1001 appear another title and so on....
That is what I want do in Ajax, the script have to read the database correspodent for that number, and present data in "<div id="config_titulos">HERE PUT THE INFORMATION COME FROM DATABASE/AJAX</div>".
The db query you see in the beginning of the code, is usually the code I use to get data from db, in this specific case "tutorial" is where located the number, and "title" is where is locates the data from title correspondent for each number.

How I do in Ajax the presentation of title for different numbers I put in the form?

The best regards, JC
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.php">
<? include("database.php"); 
// this is the way I usualy use to get data from database, in this case I get information from URL, but for this example can be any thing!
$tutorial_result = mysql_query("SELECT * FROM tutorial where tutorial = '$_GET[tutorial]'", $db);
$tutorial_rows = mysql_num_rows($tutorial_result);
$tutorial = mysql_fetch_object($tutorial_result);
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Novo Tutorial</title>
<style type="text/css" media="screen">
	@import "index.css";
<div id="geral">
<div id="titulo">upload de ficheiros e pastas</div>
<div id="sub_titulo">verificação e preparação</div>
<div id="menu_links">
<a href="index.php" class="links">home</a> <a href="novo.php" class="links">novo</a> <a href="configuracao.php" class="links">configuração</a> <a href="lista.php" class="links">lista</a>

<div id="config_tecno">
<div id="config_titulos">insert number please:</div>
<div id="form"><form action="PROCESS_INFORMATION.PHP" method="post" name="form1">
<input name="number" type="text" value="" size="10" maxlength="4" /><br /> 
<input name="button" type="submit" disabled value="send information to process" /> 

Open in new window

Watch Question
Expert of the Year 2008
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE