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



?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.