vince164 Posted October 18, 2009 Share Posted October 18, 2009 Hi i am trying to use DISTINCT to prevent duplicates but its not working $q = "SELECT DISTINCT id,name FROM links,link_img ORDER BY RAND() LIMIT 0, 6"; Quote Link to comment https://forums.phpfreaks.com/topic/178085-solved-distinct-not-working/ Share on other sites More sharing options...
Maq Posted October 18, 2009 Share Posted October 18, 2009 How is it not working? One thing I noticed is that you're using distinct on "id". If id is unique then it won't work... Quote Link to comment https://forums.phpfreaks.com/topic/178085-solved-distinct-not-working/#findComment-939010 Share on other sites More sharing options...
vince164 Posted October 18, 2009 Author Share Posted October 18, 2009 hi thanks for the reply, well its still getting duplicates and no the id is not unique, although i did manage to get it to work with only using 1 table if i pull the information from 1 table instead of 2 it will work but is there a way to pull the data from 2 tables and still have it show unique stuff i will include my code mysql tables link, link_img mysql table link_img fields id mysql link_img table fields name here is my full php code $q = "SELECT DISTINCT id,name FROM links,link_img WHERE `active`='Yes' AND `in`>'0' ORDER BY RAND() LIMIT 0, 6"; $games = get_games("shortdesc=".$themecfg['maxdesclength']."&htmlize=true&diffquery=".$q); foreach ($games as $game) { { ?> <?php echo "<div class='midpbtnin'> <a href='".get_home_link()."links/out/".("".$game['id']).".html' target='_blank'><img src='[themedir]layout/images/100x110/".$game['name']."-up.gif' onmouseover=this.src='[themedir]layout/images/100x110/".$game['name']."-down.gif'; onmouseout=this.src='[themedir]layout/images/100x110/".$game['name']."-up.gif'; alt='".$game['title']."' width='100' height='100' /></a> </div>"; ?> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178085-solved-distinct-not-working/#findComment-939048 Share on other sites More sharing options...
fenway Posted October 18, 2009 Share Posted October 18, 2009 We don't need the code -- we need to see the output that isn't "distinct". Quote Link to comment https://forums.phpfreaks.com/topic/178085-solved-distinct-not-working/#findComment-939125 Share on other sites More sharing options...
vince164 Posted October 23, 2009 Author Share Posted October 23, 2009 i got it fixed, for some reason distinct wont work if you are getting data from 2 tables so i just created a function for the other table Quote Link to comment https://forums.phpfreaks.com/topic/178085-solved-distinct-not-working/#findComment-942843 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.