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.phpHTML
http://xem.pl/Szykam osoby która mi pomoże choć w części to połączyć!
KOD php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>Look! A Poll!</title>
<script language="javascript" type="text/javascript">
function vote(id){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var file = 'vote.php?id='; //This is the path to the file we just finished making
xmlhttp.open('GET', file + id, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved
if( content != 'n' ){ //If the response was not "n" (meaning it worked)
content = content.replace('y', ''); //Get rid of the y infront of our result *
document.getElementById('option' + id).innerHTML = content; //Set the inner HTML of the div with the old value in it to the new value **
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
</script>
</head>
<body>
<p>Question? <!-- Replace with your actual question of course! --></p>
<?php
mysql_connect("localhost", "mysql_user", "mysql_pass"); //Connect to the MySQL server with your host (probably localhost), your mysql username, and your mysql password
$query = mysql_query("SELECT * FROM results ORDER BY count DESC") or
die(mysql_error()); //Query all possible options ordering by total votes {
{
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 }
}
else
{
echo "<p>Sorry, there are no options to vote for!</p>"; //Otherwise we echo out that message }
?>
</body>
</html>
Dziękuję za wszelaką pomoc!
Ten post edytował coockies1 23.09.2006, 16:16:28