joerosenthal Posted March 29, 2006 Share Posted March 29, 2006 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[code] 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;}} [/code]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. [code]return join("\n", array_slice(mysql_fetch_array($row), -2)); [/code] outputs correctly in the file but its not the output that I am looking for, so the problem isn't the javascriptany insight on this issue would be much appreciated. Quote Link to comment Share on other sites More sharing options...
toplay Posted March 29, 2006 Share Posted March 29, 2006 You can't have PHP display anything. All that PHP should be doing is passing the data back and JavaScript has to display it.I'm surprised that your query is even working as-is because it's not a good idea to use names of columns that are the same as MySQL reserved words (like date and time). I recommend changing the column names to something more meaningful that reflects what type of date and time is really for (i.e. post_date and post_time). However, if you chose to keep them the same, then enclose the column names within backtick marks. Example:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] postby, `date`, `time`, ip, msg [color=green]FROM[/color] [color=orange]chat[/color] [color=green]ORDER BY[/color] `date`, `time` [color=green]ASC[/color] [color=green]LIMIT[/color] [color=orange]0, 4[/color][!--sql2--][/div][!--sql3--] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.