English 中文(简体)
显示MySql 数据库数据
原标题:Show MySql Data from Database On date Selection from Php Using Ajax

我正在拟定一份像马普切人这样的申请。

3 采用javascript制成的表格:

Mapview
ListView
Post Events

In the list view i have to fetch data from the mysql table. the functioning has to be like this that i have a textfield onclick which user can select the date and a button for execution. once the date has been selected upon button click it has to fetch data from the database. So shall i have to use ajax in doing this? The data has to be displayed in a particular division of my html and it has to stay on the page itself once the content has to retrieved. That is the user has the provision of selecting another date. My problem is i am new to AJAX and i am only on the starter stage. Can anyone help me doing this?

问题回答
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option> 
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html> 

SECOND FILE 不结盟运动E IS Accessuser.php

<?php
$q=$_GET["q"];
$con = mysql_connect( localhost ,  peter ,  abc123 );
if (!$con)
{
die( Could not connect:   . mysql_error());
}
mysql_select_db("ajax_demo", $con);
$sql="SELECT * FROM user WHERE id =  ".$q." ";
$result = mysql_query($sql);
echo "<table border= 1 >
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row[ FirstName ] . "</td>";
echo "<td>" . $row[ LastName ] . "</td>";
echo "<td>" . $row[ Age ] . "</td>";
echo "<td>" . $row[ Hometown ] . "</td>";
echo "<td>" . $row[ Job ] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>  

this is example of listbox when u select list box related information is display using Ajax
Just u have to create database name is ajax_demo.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签