lukerodham Posted July 20, 2011 Share Posted July 20, 2011 hi, im trying to use the DISTINCT mysql command to select unique ip's that have visited my site, but im also trying to get the rest of the rows data aswell so i can output the date and time that they visited. i ran into the problem that i can output the ip but no date and time. but if i add the the 'date' in the query line i dont get a unique output as i believe the it looks for a DISTINCT ip and date then. i have the code below to help you understand a bit more. but could some please help me as i can get the right output. thanks. $unique_query = mysql_query("SELECT DISTINCT ip, date FROM ip ORDER BY date DESC LIMIT 10"); while($uniquerow = mysql_fetch_array($unique_query)){ echo "<table width='100%' border='0' align='center'> <tr> <td width='50%' align='center' valign='middle' class='aboutme'>".$uniquerow['ip']."</td> <td width='50%' align='center' valign='middle' class='aboutme'>".$uniquerow['date']."</td> </tr> </table>"; } this is the output atm. Quote Link to comment https://forums.phpfreaks.com/topic/242405-distinct-query/ Share on other sites More sharing options...
premiso Posted July 20, 2011 Share Posted July 20, 2011 What is the right output? Do you want just the latest date to 1 ip? Do you want multiple dates under the 1 ip? We need to know what your goal / desired output is here. Quote Link to comment https://forums.phpfreaks.com/topic/242405-distinct-query/#findComment-1244989 Share on other sites More sharing options...
lukerodham Posted July 20, 2011 Author Share Posted July 20, 2011 Sorry i thought i added that, what im looking for is 1 ip and its latest date. is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/242405-distinct-query/#findComment-1244990 Share on other sites More sharing options...
premiso Posted July 20, 2011 Share Posted July 20, 2011 SELECT ip, date FROM ip GROUP BY ip ORDER BY date DESC LIMIT 10 Should do it. Quote Link to comment https://forums.phpfreaks.com/topic/242405-distinct-query/#findComment-1244991 Share on other sites More sharing options...
lukerodham Posted July 20, 2011 Author Share Posted July 20, 2011 Awesome thank you, its worked but the date is incorrect, its showing a time and date from yesturday. but that ok i'll try and work out how to get the proper date. THANK YOU Quote Link to comment https://forums.phpfreaks.com/topic/242405-distinct-query/#findComment-1244994 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.