Reading only one column from SQL output as a numerical array in PHP -
i run following query:
select tagid, count(*) totaloccurrences coupon_tags group tagid order totaloccurrences desc limit 10
it returns output this:
tagid totaloccurrences ------------------------ 7 9 2 8 1 3 6 2 3 1 4 1 5 1 8 1
i can't mysql_fetch_array(mysql_query($thatquery);
because has 2 columns of data , array pulled looks garbage. how can further streamline query single column of still-sorted data, it's easier work in array? or maybe using wrong php/mysql function (although looked through them all)?
edit: i've found out query work fine in phpmyadmin fails when try query mysql_query()
.
my php code:
$tagsql = mysql_query($selectorsql); if (!$tagsql) die("query failed"); //fails here while ($tsrow = mysql_fetch_assoc($tagsql)) { var_dump($tsrow); }
you can "streamline query single column of still-sorted data".
select tagid coupon_tags group tagid order count(tagid) desc limit 10
just make sure use count on single column instead of counting everything, affect performance.
Comments
Post a Comment