Incredinot Posted March 24, 2010 Share Posted March 24, 2010 Hi.. I have this code that works just as inteded.. There is only one thing im missing, and that is to make sure that values are not postet more than once.. Ive tried with DISTINCT as you can see in the code below, but that wont do the trick.. <?php $not_allowed = 26; $butik_id = mysql_query("SELECT DISTINCT * FROM node, term_node WHERE term_node.tid != $not_allowed AND node.type = 'butikker' ORDER BY RAND() LIMIT 3"); $i = 1; while ($i <= 3) { // Get node id. $butik_id_row = mysql_fetch_array($butik_id); $id = $butik_id_row['nid']; print $id; $i++;} ?> Quote Link to comment https://forums.phpfreaks.com/topic/196339-distinct-while-loop/ Share on other sites More sharing options...
JonnoTheDev Posted March 24, 2010 Share Posted March 24, 2010 You need to specify the field name that you want to be distinct within the query. It is the first field you specify i.e SELECT DISTINCT name,userId,email FROM users The field 'name' is distinct. If it is the case that you have duplicate records in your database you should be preventing this and not writing queries to compensate. Quote Link to comment https://forums.phpfreaks.com/topic/196339-distinct-while-loop/#findComment-1030965 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.