473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

A small problem (SQL+search+array+distinct)

Hi,

I have this Mysql db:

id int(11) autoincremement prim. key
parentid int(11)
... etc .. (fields for a discussion board)

When parentid=0 then it is a new thread, otherwise it is a comment to
the thread that has the id that is in parentid (hope you get the
picture)
when I want to search, I issue: select * from forum where (something)
but then for instance I get:

ID,parentid
1,0
3,0
8,3
9,3
11,0

How do I do so:

a) all redundant PARENTID's are limited to one of each, and
b) if a parentid is equal to any id, delete the parentid

It all should end up in a list (arrray) of the ID's relevant.
In the above instance it would be:
1
3
8
9
11

ParenIDs of 0 should be ignored.

I am not very good at english, nor to explain myself, so please do not
hesitate to ask further, or send me to another news group if
appropriate.

Sincerely,

Adam
Jul 17 '05 #1
2 2210
Nevermind, I use unique_array it worked great
Jul 17 '05 #2
Adam Nørregaard <ad**************@e-mail.dk> wrote in message news:<a9********************************@4ax.com>. ..
Nevermind, I use unique_array it worked great


In PHP you can use *array_unique* function to remove duplicate values from an array.

In of MySQL fetch loop, create an array of Ids by using syntax similar to:

$id_array[] = $row['id'];
$id_array[] = $row['parentid'];

After completion remove duplicates:

$id_array = array_unique($id_array);

Now $id_array will contain only unique ids

-- Rahul
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Don | last post by:
Hi folks I wonder if someone could help me with a script I have been trying unsuccessfully to write for a while now. I have two tables - member_dest and member_det and have 3 search criteria...
7
by: Randall Parker | last post by:
Using IE 6.x (whatever is the latest) on Windows 2000. For these two CSS definitions if I remove the 2 lines that have the "mso-" font family definitions (mso-fareast-font-family, and...
4
by: Manny | last post by:
Hi, I would like to display a small html file in a layer (div) when the mouse goes over a link (<a href="small.html" onMouseOver="showPop(small.html)"). Which tag should I use in the layer :...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
7
by: Frankie | last post by:
I'm trying to run the following search query: $query = sprintf ("SELECT itemNumber, thumbnailURL, title, description, price FROM apparel,hats WHERE apparel.title OR apparel.description OR...
9
by: valeberry | last post by:
index <?php include ("conn.php"); require_once("tabs.php"); ?> <html> <head> <?php tabs_header(); ?> </head> <body>
3
by: RoomfulExpress | last post by:
Here is the URL where the code is posted: http://www.roomfulexpress.com/newsite/search/response2.php I pulled this code from: <Link removed> The code as a whole seems to make sense to me,...
16
by: timber910 | last post by:
Hello All, I've been searching for over a week and have found a good start but can't seem to make what I want work. I either get an error or a blank table. What I'm looking for. I have to make a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.