no save
Assistance
Achat
News

Forum | webmastering
[Ajax+PHP] Refresh et MySQL
xxkirastarothxx, le ven. 11 juil. 2008 à 12:04:09
Bonjour à tous,

J'ai récupéré et modifié un script de mini chat, mais depuis que je veux afficher des réponses SQL, à la place de ce qu'il y a dans un fichier txt, plus rien ne marche.
je suis spécialement mauvais en Ajax, donc si quelqu'un pouvais m'aider un peu ça serrai super :)

<?php
function afficher()
{
mysql_connect("localhost", "root", "");
mysql_select_db("chat");
$reponse = mysql_query("SELECT * FROM minichat");
while ($donnees = mysql_fetch_array($reponse))
{
echo $donnees['name'];
}
mysql_close();
}

require_once('./xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->register(XAJAX_FUNCTION, 'afficher');
$xajax->processRequest();
?>
<html>
<head>
<title>Chat xAjax</title>
<?php $xajax->printJavascript();?>
<script type="text/javascript">
function refresh()
{
xajax_afficher();
setTimeout(refresh, 5000);
}
</script>
</head>
<body>
<div id="block"></div>
<?php include "form.php"; ?>
<script type="text/javascript">
refresh();
</script>
</body>
</html>

il n'y a presque que la fonction afficher() qui change, l'originale était:
function afficher()
{
$reponse = new xajaxResponse();
$chat = '';//Initialisation de la variable $chat
$fichier_texte = fopen('./chat.txt', 'r');
$chat = fread($fichier_texte, filesize('./chat.txt'));
fclose($fichier_texte);
$reponse->assign('block', 'innerHTML', $chat);
return $reponse;
}
je suppose donc que ma fonction est complètement fausse, mais comme je l'ai dis j'y connais rien en ajax :P
Merci Beaucoup :)Configuration: Windows XP
Firefox 2.0.0.15


Alkaaran
juil. 08
Suivant
REPONSES
Alkaaran
juil. 08
xxkirastarothxx
juil. 08
Alkaaran
juil. 08
xxkirastarothxx
juil. 08
Alkaaran
juil. 08
xxkirastarothxx
juil. 08
Alkaaran
juil. 08
xxkirastarothxx
juil. 08
xxkirastarothxx
juil. 08
Alkaaran
juil. 08
Version Web
Réalisé par RedShift
no save