Jump to content

Need Help With ShoutBox


gaza165

Recommended Posts

	
<?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

<?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);



?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.