* Thus wrote Ryan A ([EMAIL PROTECTED]): > Hi, > I have a table called the_slave where i am entering differient types of data > and 5 specific "types", to get a count of each of the types i used: > > $tt = "SELECT ptype, count(*) FROM the_slave WHERE ptype IN ('1', '2', > '3','4','5') and user='".$user."' and no='".$no."' GROUP BY ptype"; > > then to dump them into variables that I could use anywhere in the page, i > used: > > if($res = mysql_query($tt)) > { > $x = 1; > while($row = mysql_fetch_row($res)) > { $var[$x++] = $row[1]; } > } > > In this way I could use it like: "Hello and welcome, you have: $var[1] of > type 1" etc
$var[1] isn't guaranteed to be of ptype '1' I would suggest to use $var[$row[0]] = $row[1]; > > now i am facing a new problem, I need to do the same as above but from 5 > differient tables (tabl1,tabl2,tabl3,tabl4 and tabl5) I can of course run 5 > select/count queries but is there a way to run just one and get the same > effect? I will need to dump it into an arrar and use it the way i used > $var[] > > Any ideas? You can use the union statement to achieve this select ptype, count(*), 'the_slave' from the_slave where ... union select ptype, count(*), 'table1' from table1 where ... ... http://www.mysql.com/doc/en/UNION.html Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php