PDA

View Full Version : problem with php and ajax


joerosenthal
03-29-2006, 04:28 AM
I am using ajax to automatically reload the content from my mysql database on a given interval without refreshing the page. The code to display the rows from mysql is totally functional but once put into the function below

function refresh() {
mysql_connect(localhost,username,password) or die(mysql_error());
mysql_select_db(main) or die(mysql_error());
$query = "SELECT postby,date,time,ip,msg FROM chat ORDER BY date,time ASC LIMIT 0,4;";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result))
{
list($postby, $date, $time, $ip, $msg) = $row;
$postby = htmlspecialchars($postby);
$msg = htmlspecialchars($msg);
$msg = nl2br($msg);
echo $ip;
}
}

the page no longer reloads nor shows the mysql query. after troubleshooting, i noticed that echo and print seem to disrupt the javascript from working. upon removing the echo command the database is reloaded. even a simple echo of "text" brings the script to a failure.

return join("\n", array_slice(mysql_fetch_array($row), -2)); outputs correctly in the file but its not the output that I am looking for, so the problem isn't the javascript

any insight on this issue would be much appreciated.

V@no
03-29-2006, 05:06 AM
Did you check javascript console? Somehow it seems to be javascript related, perhaps the AJAX function you are using is expecting XML format of the data...