Problem with getRandomProducts Function
Hi, I'm having a problem with the getRandomProducts function in that I can only get one product to display even though the products table has four items in it, including the Main Feature (which works fine).
I've tried to troubleshoot this and did a print_r to a test view and got the following printout (see below). As you can see below, the result_array shows the entire array (three records) as I would expect, but only the last record (record 4, Men's Pants) displays.
The foreach loop in the getRandomProducts function should add the results of the query of the products table into the $temp array. The rest should randomize the results and put them in the right-hand column via the home.php view (at least that's my understanding of how the process works). What I don't understand is how the data are available in the result_array function but fails to display when it's transferred to the view. Below is the result of my print_r printout. Please not that array elements 0, 1, and 2 appear, but the bottom shows only 2. Why???
(
[Q] => CI_DB_mysql_result Object
(
[conn_id] => Resource id #34
[result_id] => Resource id #46
[result_array] => Array
(
[0] => Array
(
[id] => 2
[name] => Shoes 1
[thumbnail] => images/american_flag3.jpg
[category_id] => 2
)
[1] => Array
(
[id] => 3
[name] => Men's Shoes
[thumbnail] => images/american_flag3.jpg
[category_id] => 2
)
[2] => Array
(
[id] => 4
[name] => Men's Pants
[thumbnail] => images/american_flag3.jpg
[category_id] => 2
)
)
[result_object] => Array
(
)
[current_row] => 0
[num_rows] => 3
[row_data] =>
)
[bool] => true
[2] => Array
(
[id] => 4
[name] => Men's Pants
[thumbnail] => images/american_flag3.jpg
)
)
|