I'm trying to dynamically create a select dropdown menu with optgroup. the data would come from 2 separate data tables: activities
and client_list
activities
:
client_list
:
I need a single dropdown that would display the client name and the product. with client_name
as the optgroup label and product
as the option value.
what I tried doing is I left joined the two tables.
QUERY:
SELECT a.client_name, a.product
FROM activities a
LEFT JOIN client_list c ON a.client_name = c.client_name
ORDER BY a.client_name ASC;
This is my attempt at creating the dropdown menu.
PHP:
<?php
$get='SELECT a.client_name, a.product
FROM activities a
LEFT JOIN client_list c
ON a.client_name = c.client_name
ORDER BY a.client_name ASC';
$result=mysql_query($get);
$row=mysql_fetch_array($result);
foreach($result as $results) {
$row[$results['client_name']][$results['product'] = $results['product']];
}
?>
I've tried the ff: (1), (2), and (3). I'm not sure what I'm doing wrong
How can I achieve this through php or even jquery? Also, can this be done without joining the table? I saw this wordpress article and I think it's exactly what I need but it didn't explain how it was done.
I would like to note that not all clients in the client_list
are listed in activites
so i can't use the activities
table alone. I would also like to note that I have no choice but to use mysql as the company I'm in still utilizes it. I am aware of the problems with it. Thank you!