Jump to content

Distinct while loop?


Incredinot

Recommended Posts

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++;} ?>

Link to comment
https://forums.phpfreaks.com/topic/196339-distinct-while-loop/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/196339-distinct-while-loop/#findComment-1030965
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.