Jump to content

SQL Query + Ignore Duplicates.


Reece S

Recommended Posts

Hi, I have a database, that creates a new row for every public chat room that gets created (Gets deleted when chat finishes) and even if a user enters the same chat room, it creates a new row, both with same room, but 2 users. this results in "2 Row Count" and when printed, looks like 2 chat rooms, when it is really one.

 

Is there a way to run the query but class all duplicates as one? (on a selected Column)

 

Here is my current code:

 

$result = mysql_query("SELECT * FROM ajaxim_chats");
$num_rows = mysql_num_rows($result);
echo "<strong>Public Chatrooms: </strong>$num_rows";

Link to comment
Share on other sites

What exactly are you trying to do.

 

If I was writing an ajax chat room base system I'd have a few tables

 

1) Users (login info user info etc)

2) Chat rooms (The actual room Name)

3) Chats (Postings that are defined to a given chat room ID in table 2)

4) User_in_rooms (Puts a user in a room by adding a row)

 

Then for your question you only need query off the second item.  If a table hasn't had a post added or use in it in 2 minutes destroy the room and its chat and remove all users in it (similar to a users online script)

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.