Login Register






[ASK] execute mysql in php filter_list
Author
Message
[ASK] execute mysql in php #1
good day Smile

I have something to ask,
so I want to declare an 2 dimensional associative array.
and put data into it using 2 different query.

Code:
class Log{ $genre_count = array(); $year; function __construct($year) { $this->year = $year; $query = "SELECT book_type FROM tb_book_type"; $result = mysql_query($query); if(mysql_num_rows($result)>0){ while($row = mysql_fetch_array($result)){ $this->genre_count[$row['book_type']] = array(); $querycat = "SELECT YEAR(log_date) AS 'year',MONTHNAME(log_date) AS 'month' FROM tb_log_rent WHERE YEAR(log_date)='".$year."'GROUP BY MONTHNAME(log_date)"; $resultCat = mysql_query($querycat); if (mysql_num_rows($resultCat)>0) { while ($cat = mysql_fetch_array($resultCat)) { $this->genre_count[$row['book_type']][$cat['month']] ="0"; } } } } } }



I used those to get a 2 dimension array storing [type_of_book][month] and set the data to '0' for later use in my graph.

And it works.
But still, is there any better way to do this?
I mean for better performance.
thanks.

Reply