gaza165 Posted May 10, 2009 Share Posted May 10, 2009 <?php $time_start = microtime(true); $sql = "SELECT * FROM chat WHERE chat_id > $lastid"; $result = mysql_query($sql); $time_end = microtime(true); $time = ($time_end - $time_start); ?> Im using this code to bring back records from my shoutbox, what i would like to do...when the user posts a message for it to be displayed to them straight away, and then bring it back from the database. So what I am trying to do is write an SQL statement that brings back all the other messages apart from the ones that are submitted by the user user that is logged in. Can anyone help me. thanks Garry Link to comment https://forums.phpfreaks.com/topic/157571-need-help-with-shoutbox/ Share on other sites More sharing options...
Axeia Posted May 10, 2009 Share Posted May 10, 2009 Something like WHERE user_id != $userid behind it? Bit hard without knowing what your database structure looks like Link to comment https://forums.phpfreaks.com/topic/157571-need-help-with-shoutbox/#findComment-830944 Share on other sites More sharing options...
gaza165 Posted May 10, 2009 Author Share Posted May 10, 2009 <?php session_start(); header("Expires: Mon, 26 Jul 1987 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); include ('dbconnect.php'); $nick = $_GET['nick']; $message = $_GET['message']; $lastid = $_GET['lastid']; if ($lastid == 0) { $sql = "SELECT MAX(chat_id) FROM chat"; $res = mysql_query($sql); $lastid = mysql_fetch_row($res); $lastid = $lastid[0]; } $time_start = microtime(true); $sql = "SELECT * FROM chat WHERE chat_id > $lastid AND nick != $nick"; $result = mysql_query($sql); $time_end = microtime(true); $time = ($time_end - $time_start); $sql = "SELECT MAX(chat_id) FROM chat"; $res = mysql_query($sql); $lastid = mysql_fetch_row($res); $lastid = $lastid[0]; while ($row = mysql_fetch_array($result)) { $data = array('id'=>$row['chat_id'] , 'nick'=>ucfirst($row['nick']), 'message'=>$row['message'], 'time'=>$time); } $json = '{"latest":"'.$lastid.'","response":['; $json .= json_encode($data); $json .= ']}'; echo $json; $get = "SELECT * FROM chat"; $result = mysql_query($get); $numrows = mysql_num_rows($result); ?> Link to comment https://forums.phpfreaks.com/topic/157571-need-help-with-shoutbox/#findComment-830947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.