|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?php $q=$_GET["q"]; // $con = mysql_connect('localhost', 'peter', 'abc123'); $con = mysql_connect('localhost:/tmp/mysql5.sock', 'dboxxx', 'passxxx'); 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); ?> |
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="getuser.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } |
|
|
HTML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<html> <head> <script type="text/javascript" src="selectuser.js"></script> </head> <body> <form> Select a User: <select name="users" onchange="showUser(this.value)"> <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> |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//DE" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript"> <link rel="stylesheet" type="text/css" media="all" href="css/style.css" /> <title>Beispiel</title> <script type="text/javascript" src="selectuser.js"></script> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/fabtabulous.js"></script> <script type="text/javascript" src="js/tablekit.js"></script> </head> <body> <form> Ihr Alter: <select name="users" onChange="showUser(this.value)"> <option value="">bitte wählen Sie Ihr Alter</option> <option value="10">10 Jahre</option> <option value="30" selected>30 Jahre</option> <option value="31">31 Jahre</option> <option value="32">32 Jahre</option> <option value="33">33 Jahre</option> <option value="34">34 Jahre</option> <option value="35">35 Jahre</option> <option value="36">36 Jahre</option> <option value="37">37 Jahre</option> </select> </form> <br /> <div id="txtHint"><b>Die Tarifbeiträge werden nach der Altersauswahl hier angezeigt.</b></div> <br /> <table class='sortable resizable'> <thead> <tr> <th id='adf_gesellschaft'>Gesellschaft</th> <th id='adf_tarif'>Tarif</th> <th id='adf_alter'>Alter</th> <th id='adf_beitrag'>Beitrag</th> <th class='sortfirstdesc' id='adf_leistungsstaerke'>Leistungsstaerke</th> </tr> </thead> <tfoot> <tr> <td>Gesellschaft</td> <td>Tarif</td> <td>Alter</td> <td>Beitrag</td> <td>Leistungsstaerke</td> </tr> </tfoot> <tbody> <tr> <td>B-Gesellschaft</td> <td>B-Tarif</td> <td>20</td> <td>15,00 € </td> <td>888</td> </tr> <tr> <td>C-Gesellschaft</td> <td>C-Tarif</td> <td>30</td> <td>20,00</td> <td>777</td> </tr> <tr> <td>A-Gesellschaft</td> <td>A-Tarif</td> <td>10</td> <td>10,00 €</td> <td>999</td> </tr> </tbody> </table> </body> </html> |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<?php include ("configuration.php"); $q=$_GET["q"]; // $con = mysql_connect('localhost', 'peter', 'abc123'); $con = mysql_connect($host, $dbuser, $dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $sql="SELECT * FROM $table WHERE adf_alter = '".$q."'"; $result = mysql_query($sql); // Tabellen Überschriften und Beschriftungen in der Fußzeile echo "<table class='sortable editable resizable'> <thead> <tr> <th class='sortfirstdesc' id='adf_gesellschaft'>Gesellschaft</th> <th id='adf_tarif'>Tarif</th> <th id='adf_alter'>Alter</th> <th id='adf_beitrag'>Beitrag</th> <th id='adf_leistungsstaerke'>Leistungsstaerke</th> </tr> </thead> <tfoot> <tr> <td>Gesellschaft</td> <td>Tarif</td> <td>Alter</td> <td>Beitrag</td> <td>Leistungsstaerke</td> </tr> </tfoot> "; // // Inhalte in Tabelle einfügen while($row = mysql_fetch_array($result)) { echo "<tbody>"; echo "<tr>"; echo "<td>" . $row['adf_gesellschaft'] . "</td>"; echo "<td>" . $row['adf_tarif'] . "</td>"; echo "<td>" . $row['adf_alter'] . "</td>"; echo "<td>" . $row['adf_beitrag'] . "</td>"; echo "<td>" . $row['adf_leistungsstaerke'] . "</td>"; echo "</tr>"; echo "</tbody>"; } echo "</table>"; echo "<script type='text/javascript' src='js/prototype.js'></script>"; echo "<script type='text/javascript' src='js/fabtabulous.js'></script>"; echo "<script type='text/javascript' src='js/tablekit.js'></script>"; // mysql_close($con); ?> |
|
|
PHP Quellcode |
1 |
$sql="SELECT * FROM $table WHERE adf_alter = '".mysql_real_escape_string($q)."'"; |
This post has been edited 2 times, last edit by "Deadman44" (Dec 1st 2009, 2:38pm)
Quoted
Bei meiner uche ist immer das evalScripts als Lösung verwendet worden, allerdings keine Ahnung wie ich das einbaue...... :-(
Quoted
If you use evalScripts: true, any inline <script> block will be evaluated. This does not mean it will be evaluated in the global scope
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 |
function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; TableKit.load('adf_tabelle1'); } } |