Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php HTML] Potrzebuje pomocy!
Forum PHP.pl > Forum > XML, AJAX > AJAX
coockies1
Witam! Jestem pocz±tkuj±cy i mam problem z po³±czenien php , htmla i ajaxa!
Próbuje stworzyæ listê przebojów! Mam wszystko co mi jest potrzebne i dzia³a bez problemu, ale psobno.
WZÓR!
php i AJAX http://xem.pl/index_2.php
HTML http://xem.pl/

Szykam osoby która mi pomo¿e choæ w czê¶ci to po³±czyæ!
KOD php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  5. <title>Look! A Poll!</title>
  6. <script language="javascript" type="text/javascript">
  7. function vote(id){
  8. var xmlhttp=false; //Clear our fetching variable
  9. try {
  10. xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
  11. } catch (e) {
  12. try {
  13. xmlhttp = new
  14. ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
  15. } catch (E) {
  16. xmlhttp = false;
  17. }
  18. }
  19. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  20. xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
  21. }
  22. var file = 'vote.php?id='; //This is the path to the file we just finished making
  23. xmlhttp.open('GET', file + id, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
  24. xmlhttp.onreadystatechange=function() {
  25. if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
  26. var content = xmlhttp.responseText; //The content data which has been retrieved
  27. if( content != 'n' ){ //If the response was not "n" (meaning it worked)
  28. content = content.replace('y', ''); //Get rid of the y infront of our result *
  29. document.getElementById('option' + id).innerHTML = content; //Set the inner HTML of the div with the old value in it to the new value **
  30. }
  31. }
  32. }
  33. xmlhttp.send(null) //Nullify the XMLHttpRequest
  34. return;
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <p>Question? <!-- Replace with your actual question of course! --></p>
  40. <?php
  41. mysql_connect("localhost", "mysql_user", "mysql_pass"); //Connect to the MySQL server with your host (probably localhost), your mysql username, and your mysql password
  42. mysql_select_db("db_name"); //Select your MySQL database by name
  43.  
  44. $query = mysql_query("SELECT * FROM results ORDER BY count DESC") or die(mysql_error()); //Query all possible options ordering by total votes
  45. if( mysql_num_rows($query) ) //If there are any results to show...
  46. {
  47. while( $row = mysql_fetch_array($query) ) //Begin a loop to echo out each option
  48. {
  49. echo '<br /><strong>'. $row['option']. ' <a href="java script:vote('. $row['id']. ')">Vote!</a></strong><div id="option'. $row['id']. '">'. $row['count']. '</div>'; //Echo out each option, vote link, and total votes
  50. }
  51. }
  52. else
  53. {
  54. echo "<p>Sorry, there are no options to vote for!</p>"; //Otherwise we echo out that message
  55. }
  56.  
  57. ?>
  58. </body>
  59. </html>


Dziêkujê za wszelak± pomoc!
dr_bonzo
1. Dla ajaxu jest specjalne forum, gdzie przenosze
2. szukasz osoby (nie to forum -> geilda ofert), czy rozwiazania problemu?
3. Popraw temat -- nie posiada on zadnej tresci, nie opisuje problemu
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.