Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.