Selecting category details and products linked with the same category. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Selecting category details and products linked with the same category. (/showthread.php?tid=38295) Pages:
1
2
|
Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] i want to list car category name and car details in a single page but the result is car details are same for every category.... can anyone help me ..... thanks in advance controller Code: function index() model Code: function select_fleets() Code: <?php foreach($fleets as $row) Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]cideveloper[/eluser] First thing. Please use code blocks for your code. Makes it much easier to read. like this Controller Code: code here... Code: code here... Code: code here... Now on to your question. From the looks of you code am I correct in saying that for each category displayed the result is all the car names from the last category. Category 1 ------------ Car_name_1_from_Category_3 Car_name_2_from_Category_3 Car_name_3_from_Category_3 Category 2 ------------ Car_name_1_from_Category_3 Car_name_2_from_Category_3 Car_name_3_from_Category_3 Category 3 ------------ Car_name_1_from_Category_3 Car_name_2_from_Category_3 Car_name_3_from_Category_3 If I am correct, it is because of this Code: foreach($fleets as $row) from this code it looks like every time you loop you are overwriting $this->data['listefleets'] so by the time you call the view your $this->data['listefleets'] only has the info from the last loop Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] how do i solve this problem??? Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] Try: Code: foreach($fleets as $row) Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] but it shows error in the view page Message: Trying to get property of non-object is there any change in the view page???? Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] Use <pre><?php print_r($variable);?></pre> to see what you've to render (an array). Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] it shows the same car details in every categories Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]InsiteFX[/eluser] Show your databse table structure, that could be the problem! When dealing with categories any sub-categories need to have a parent_id pointing to the main category. InsiteFX Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] can u help me?? i didn't used parent id till this time table car_category Code: category_id, category_name, details, photo table cars Code: id, car_name, category_id, description if i use parentid how i write query??? thanks in advance.... Selecting category details and products linked with the same category. - El Forum - 02-04-2011 [eluser]Bigil Michael[/eluser] Group D Daily Rate (AED) Weekly Rate (AED) Monthly Rate (AED) View Details YARIS - 2011 100 630 2100 Click here Lancer - 2010 100 600 1850 Click here Group C Daily Rate (AED) Weekly Rate (AED) Monthly Rate (AED) View Details YARIS - 2011 100 630 2100 Click here Lancer - 2010 100 600 1850 Click here Group A Daily Rate (AED) Weekly Rate (AED) Monthly Rate (AED) View Details YARIS - 2011 100 630 2100 Click here Lancer - 2010 100 600 1850 Click here this is the result iam getting. car group(category) name is different but car details are repeating can any one help me??? urgent.... |