Davie33 Posted May 22, 2012 Share Posted May 22, 2012 Hi am having a few problems solving this code with select distinct clause. None of what i tryed works. Can anyone help please thanks. this is just some of the query's i tryed $query7 = yasDB_select("SELECT DISTINCT * FROM useronline WHERE id;"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline WHERE id;"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline WHERE ip;"); $query7 = yasDB_select("SELECT DISTINCT ip,timestamp FROM useronline WHERE id;"); $query7 = yasDB_select("SELECT DISTINCT id,ip,timestamp FROM useronline WHERE id;"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline;"); and again but without ";" $query7 = yasDB_select("SELECT DISTINCT * FROM useronline WHERE id"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline WHERE id"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline WHERE ip"); $query7 = yasDB_select("SELECT DISTINCT ip,timestamp FROM useronline WHERE id"); $query7 = yasDB_select("SELECT DISTINCT id,ip,timestamp FROM useronline WHERE id"); $query7 = yasDB_select("SELECT DISTINCT ip FROM useronline"); this is the code am working on. $query7 = yasDB_select("SELECT DISTINCT * FROM useronline WHERE id;"); $visitors_online = $query7->fetch_array(MYSQLI_ASSOC); $visitors_online = $query7->num_rows; $query7->close(); visitors online : <?php echo $visitors_online;?><br/> Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/ Share on other sites More sharing options...
TOA Posted May 22, 2012 Share Posted May 22, 2012 If your just trying to get the unique id's, it's: SELECT DISTINCT(id) FROM useronline Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/#findComment-1347477 Share on other sites More sharing options...
Davie33 Posted May 22, 2012 Author Share Posted May 22, 2012 If your just trying to get the unique id's, it's: SELECT DISTINCT(id) FROM useronline am trying to get the count working but nothin i do works even when i try something like this SELECT DISTINCT count(id) as count FROM useronline or SELECT DISTINCT count(id) as count FROM useronline WHERE id Thanks on the query doesnt work tho thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/#findComment-1347480 Share on other sites More sharing options...
TOA Posted May 22, 2012 Share Posted May 22, 2012 SELECT COUNT(DISTINCT(id)) AS count FROM usertable This will tell you how many unique ids are logged in usertable Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/#findComment-1347481 Share on other sites More sharing options...
Davie33 Posted May 22, 2012 Author Share Posted May 22, 2012 Hi its showing as only one online visitors online : 1 there is a few online atm its odd man cos the code i was using works on test server localhost which is this $query7 = yasDB_select("SELECT DISTINCT ip,timestamp FROM useronline WHERE id;"); $visitors_online = $query7->fetch_array(MYSQLI_ASSOC); $visitors_online = $query7->num_rows; $query7->close(); Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/#findComment-1347482 Share on other sites More sharing options...
Davie33 Posted May 22, 2012 Author Share Posted May 22, 2012 Hi iwould like to thank those who helped me in trying to solve this.The code works fine now as it was not the code that was the problem it was cos i missed out a file that should have been upload so i do apologize for that and thanks again people. Quote Link to comment https://forums.phpfreaks.com/topic/262897-select-distinct-help-please/#findComment-1347716 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.