Re: Php - union

From: Date: Fri, 08 Aug 2003 10:57:38 +0000
Subject: Re: Php - union
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-158802@lists.php.net to get a copy of this message
You could try... SELECT 'Count1', COUNT(*) FROM table1 WHERE cno = 3 UNION SELECT 'Count2', COUNT(*) FROM table2 WHERE cno = 3 UNION etc. At least you could fill an array to see what was missing. "Ryan A" <ryan@jumac.com> wrote in message news:000f01c35d4e$8c22d0b0$f081aa51@l2zcaxu7emppqh... > Hi, > In my php script i am running a sql statement, > I am using a union statement via a count to get the number of records from 5 > differient tables with the cno=3, its working fine except for one thing, if > the any one of the tables dont have cno=3 it does not give me back a zero. > Heres what i am doing: > $theResult="SELECT COUNT(*) FROM table1 WHERE cno = 3 > UNION > SELECT COUNT(*) FROM table2 WHERE cno = 3 > UNION > SELECT COUNT(*) FROM table3 WHERE cno = 3 > UNION > SELECT COUNT(*) FROM table4 WHERE cno = 3 > UNION > SELECT COUNT(*) FROM table5 WHERE cno = 3"; > > this will return 5 rows in result, f.e.: > > COUNT(*) > -------- > 12 > 10 > 9 > 23 > 7 > > but if table1 didnt have cno=3 it gives me: > COUNT(*) > -------- > 10 > 9 > 23 > 7 > > I am sure this must have been a problem with you guys to so how did you > solve it? how can i know (in my script) if its contains a positive number or > is 0? > I can run 5 counts but that would be a waste of connections if the site gets > a lot of members (which by the looks of it, it will). > > Any help appreciated, thanks in advance. > > Cheers, > -Ryan > > > We will slaughter you all! - The Iraqi (Dis)information ministers site > http://MrSahaf.com > >

« previous php.general (#158802) next »