Reece S Posted February 9, 2008 Share Posted February 9, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/ Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462868 Share on other sites More sharing options...
Reece S Posted February 9, 2008 Author Share Posted February 9, 2008 I do have other tables, and I know exactly how each one works, but The part I am focusing on is this. I have a number of successfully queries running like this, but for this particular one, I need to ignore a columns duplicates. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462871 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 you can use UNIQUE() but I'm trying to save you from killing yourself with poor strucutre Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462881 Share on other sites More sharing options...
Reece S Posted February 9, 2008 Author Share Posted February 9, 2008 Yeah true, but I am just trying to get a basic system working. I really appreciate your intentions, BTW thanks for the UNIQUE() thing, I will try it now. When my system collapses, al bear your warning in mind. Cheers again. Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462886 Share on other sites More sharing options...
Reece S Posted February 9, 2008 Author Share Posted February 9, 2008 Um... where exactly do I put this??? Does it need a WHERE statement? Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462895 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 <?php $q = "Select UNIQUE('FIELDNAME') as 'FIELDVALUES' from `TABLE` Where This = that"; ?> Generic useage Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462897 Share on other sites More sharing options...
Reece S Posted February 9, 2008 Author Share Posted February 9, 2008 ahh, thanks. I am useless with PHP, I was experienced with C/C++. Cheers man. Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462898 Share on other sites More sharing options...
Reece S Posted February 9, 2008 Author Share Posted February 9, 2008 Quick Notice: This problem was solved with this: SELECT DISTINCT(column name) FROM table name Cheers anyway. Hope this helps other people with same problem. Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462918 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 DISTINCT AND UNIQUE are similar but different Quote Link to comment https://forums.phpfreaks.com/topic/90279-sql-query-ignore-duplicates/#findComment-462922 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.