->result() not showing all rows/data |
Hi all, I have a question
Let say we have this 2 tables in our database first table : category_lists category_lists_id | category ============================ 1 | Accident Management 2 | Aluminium 3 | Brass 4 | Car Services 5 | Car Towing 6 | Car Wreckers 7 | Cash For Cars second table: data_category id | list_data_id | category_lists_id =================================== 1 | 3 | 5 2 | 3 | 6 3 | 3 | 7 4 | 2 | 8 5 | 4 | 5 6 | 1 | 6 7 | 1 | 7 so if list_data_id is equal to 1 meaning that it has 2 data if you look at data_category table which is 6 and 7 Now what I want is to query from category_list table so that 6 and 7 will echo Car Wreckers and Cash For Cars. This is what my code looks like: below is my controller PHP Code: public function index($listing_name) below is my model PHP Code: public function get_ads($list_id) below is my view: Code: <?php foreach ($category_ads as $value) { ?> with the code above I get only 1 data which is Car Wreckers as you can see from the table it suppose to show 2 data Car Wreckers and Cash For Cars Can anyone help me with this? Thank You
[quote pid='365920' dateline='1562724737']
PHP Code: foreach ($query as $value) { [/quote] I did not read all your question BUT why there is return statement in your foreach loop? Also you should learn SQL, this is not the right of doing such a query. Learn about JOIN clause in SQL, this is basics and power of RDBMS. It will take some time to learn, but it is what everybody has to do.
Have a look at the Database Reference in the CI documentation.
Use the JOIN statement to get the result from 2 tables. (07-09-2019, 07:12 PM)acebay Wrote: Hi all, I have a questionhai, This is called under the topic of dynamic dependent drop down list. Search in the google https://www.webslesson.info/2018/06/code...-ajax.html It helps you. |
Welcome Guest, Not a member yet? Register Sign In |