List:General Discussion« Previous MessageNext Message »
From:Gavin Towey Date:February 16 2010 7:25pm
Subject:RE: count children nodes
View as plain text  
Trees can be complex in SQL; these articles will give some different ideas to handle it:

Gavin Towey

-----Original Message-----
From: David Arroyo Menendez [mailto:david.arroyo@stripped]
Sent: Tuesday, February 16, 2010 8:27 AM
To: mysql@stripped
Subject: count children nodes


I've the next table structure:

CREATE TABLE tx_cc20_mensajes (
    uid int(11) NOT NULL auto_increment,
    pid int(11) DEFAULT '0' NOT NULL,
    tstamp int(11) DEFAULT '0' NOT NULL,
    crdate int(11) DEFAULT '0' NOT NULL,
    cruser_id int(11) DEFAULT '0' NOT NULL,
    deleted tinyint(4) DEFAULT '0' NOT NULL,
    hidden tinyint(4) DEFAULT '0' NOT NULL,
    remitente int(11) DEFAULT '0' NOT NULL,
    destinatario int(11) DEFAULT '0' NOT NULL,
    padre int(11) DEFAULT '0' NOT NULL,
    mensaje text,
    leido tinyint(3) DEFAULT '0' NOT NULL,

    PRIMARY KEY (uid),
    KEY parent (pid)

Where padre is the id of the parent message. I need count the messages don't
read in a thread. How can I do it?

$query="select count(*) as num from tx_cc20_mensajes msj where hidden=0 and
deleted=0 and leido=0 and destinatario=".$uid." and remitente<>".$uid." and
(padre=".$est_row['uid']." or uid=".$est_row['uid'].")";
I am counting only the first level, but I need count the rest of children
messages. What is the query?


This message contains confidential information and is intended only for the individual
named.  If you are not the named addressee, you are notified that reviewing,
disseminating, disclosing, copying or distributing this e-mail is strictly prohibited. 
Please notify the sender immediately by e-mail if you have received this e-mail by mistake
and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore does not accept
liability for any loss or damage caused by viruses or errors or omissions in the contents
of this message, which arise as a result of e-mail transmission. [FriendFinder Networks,
Inc., 220 Humbolt court, Sunnyvale, CA 94089, USA,
count children nodesDavid Arroyo Menendez16 Feb
  • RE: count children nodesGavin Towey16 Feb
  • Re: count children nodesPeter Brawley16 Feb
    • Re: count children nodesDavid Arroyo Menendez17 Feb