So I am new to this and I wanted to use the ID of my li elements to make a request to SQL but realized too late that was not possible. Now I am stuck and I don't know how to proceed other than by doing this the long way and coding each li individually.
Here is my code:
<li style="float: right;">Themes
<ul>
<?php
$id_count = 0;
$db=mysql_connect('localhost','root','');
if(!$db) {
die('Could not connect: '.mysql_error());
}
$connection_string=mysql_select_db('Mydb',$db);
$selectSQL='SELECT * FROM color_patterns';
$queryset=mysql_query($selectSQL);
$num=mysql_num_rows($queryset);
if(0==$num) {
echo "No record";
exit;
} else {
while($row=mysql_fetch_assoc($queryset)) {?>
<li id="<?php echo($id_count) ?>" onclick="
$sql='SELECT * FROM color_elements WHERE pat_ID = "the index of the li"';
$query=mysql_query($sql);
$hex1 = "hex code in row 1"
$hex2 = "hex code in row 2"
$hex3 = "hex code in row 3"">
<?php echo($row['name']);
$id_count++;
?></li><?php
}
}
?>
</ul>
</li>
The themes list element has a dropdown list which is populated by the while loop (it creates a new li for each row in the table color_patterns and puts the name of the row as the title of the li, this part works perfectly). Now when the user clicks on one of the li in the dropdown I wanted to send a SQL request to the color_elements table where the id = "the clicked li index" and it will retrieve a table with 3 rows and and I would assign the value in the "hex_code" column from each row to one of 3 php variables. I can't think of anyway to do this (mainly send the clicked li index to SQL) is it possible or will I have to do it another way (I know another way but it's ugly and long).
For example: My color_patterns table has 2 rows with names A and B,
the while loop creates 2 li labeled one labeled A and the other B, When the user clicks A a sql command is run:
$sql='SELECT * FROM color_elements WHERE pat_ID = 1'; //here 1 is the index of A
this returns a table with 3 rows and I use the "hex_code" column to assign $hex1,$hex2,$hex3 values based on the 1st, 2nd and 3rd row.
Any help at all is appreciated. Thank you.