PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
So pretty much I have two arrays from the database, one for all the platforms that exist and one for all the products.
I need to show all platforms in a <select multiple> and mark as selected any platform that existed in the entry.
Field 'os' in table accepts the values space separated like "5 7 9"
Sindarin wrote:Field 'os' in table accepts the values space separated like "5 7 9"
That's a red flag right there. You're storing multiple values in a single column?
You may want to create a new array for all the os column values. Iterate over your query results, explode out your os column values, check if they already exist in your new array and add them if they don't. Once that's done, you can use the new array to populate your select list.
I don't really get the table structure above, do I need 3 tables to join? Will this save me an extra query to query once the products and once the product_platforms tables?
Sindarin wrote:I don't really get the table structure above, do I need 3 tables to join? Will this save me an extra query to query once the products and once the product_platforms tables?
As Celauran showed, the usual way to implement these kinds of relations is to have an intermediate link table. Like Celauran show, that table is usually named by combining both table names like table1_table2. In the link table are key pairs for the keys for each table. So each record in the link table connects one record in table1 with one record in table2. To fetch results you JOIN the link table with one or both data tables and SELECT WHERE either table1_id or table2_id is equal to a specific value.