Start New Discussion within our Web Development Community
  `ID` mediumint(9) NOT NULL AUTO_INCREMENT,
  `username` varchar(60) DEFAULT NULL,
  `password` varchar(60) DEFAULT NULL,

  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `from` varchar(250) NOT NULL,
  `to` varchar(250) NOT NULL,
  `message` text NOT NULL,
  `timestamp` datetime NOT NULL,
  PRIMARY KEY (`id`)

   $query =("SELECT * FROM  users ");
   $result = mysql_query($query);

   while ($row = mysql_fetch_assoc($result))
    echo"<a href='chat.php'>$users</a><br>";    

Above while loop gives users from database.
How to chat with one or multiple users listed inside anchor tag?

no it's only database I'm using to collect information

Okay, it's really unclear what you want to do...

I'm guessing you want some kind of message board, is this correct?

If so, you'd need a page that has something like "chat.php?id={id}" and then select/post messages to the table depending on it's ID..

   // chat.php
   $id = $_GET['id'];

   // include mysql connection data

   // query the database:
      $query = "SELECT * FROM chat WHERE id='$id'";
      $result = mysql_query($query);
      if(mysql_affected_rows() >= 1)
          // display the chat
        echo 'There are currently no messages';

Something along those lines?

this helped little.
I'm creating something like gmail chat.

BTW, thanks.


But how would you do it via realtime? How will you alert the user that they have another message?

I would start with something easier, something like a private messaging system (This will give you a rough idea of how to create something simular).

So I'm guessing your using cookies/sessions?


    // connection information
    // connection information

        $query = "SELECT * FROM chat WHERE to='{$_SESSION['user_id']}'";
        $result = mysql_query($query);
        if(mysql_affected_rows() >= 1)
           while($row = mysql_fetch_array($result))
              // Here you can display the actual message "gmail"
              // or create a link (like the previous post) that contains the message.

           echo 'No new messages';

Hope this helps. Look into "polling"/"Sockets" if you want something realtime.

This is for receiving message but how to send message?

Just get this one {URL SNIPPED} and problem solved, you seem like a bad coder so you should probably take a look how others done it before. Maybe i'll get rep- but who cares..


How to send message? is meant for How to create chat window on click, for each user selected, to send message like gmail chat?

yes, can you help me for coding to send message to selected user?

There's some type of bug ... you're posting a legit site, but for some reason the hover is showing an asian porn site of some kind!

I agree. When I investigated further (not trying to look at Asian porn sites, I assure you!), the link to the offending thumb only seemed to happen if the entire url without the urlencoded & was entered. Using just the id or just the url parameteres in the querystring did not show the image. Similarly taking out the v or w parameters stopped the image from appearing. WHen I searched for the blueimp url in, it said coming soon, so it doesn't appear to have been previously referenced. However, I may be wrong - I frequently am.


I don't think the search function is working as search for referenced sites. So disregard my last bit of nonsense. :(

OK, back to the thread. Sorry for going off-piste.

The blueimp chat is very good and I've used it myself in a few projects. However, if you are determined to roll your own - a great way to develop your skills as it's not very difficult to get going, but takes time to get it to look and work like you need. One of the bigegst problems IMO is resources. Ajax is all well and good, but you still need to check the server for posts periodically (pull). There is a similar method out there called comet, which pushes data from the server. It's sometimes called "long polling". The APE project has some nice examples, although it's not that straightforward.

By now there are a number of different 'push' technologies, but I'm no expert on these I'm afraid.


forgot to mention - Comet - it uses javascript on both server and client - not php

I've reported the bug to

At the time when post was reported, I actually opened that link and it was going to porn site. Hence reason for infraction

This article has been dead for over six months. Start a new discussion instead.