I have a table:
I have a list of id's that I have selected (highlighted)
Using php and mysqli, how can I output data to the page (sorted by decending 'value', followed by the respective 'value's ascending 'name') in the most query-efficient way.
Example:
Try this ($myIDArray is from a previous query):
$myIDArray = [2,5,6,7,9,11]; //From previous query
$sql = "SELECT value, GROUP_CONCAT(name ORDER BY name DESC SEPARATOR ',')
FROM your_table
WHERE value IN (".implode(',', $myIDArray)."
GROUP BY value
ORDER BY value DESC";
After you get the result set, go through each row of the result and do something like this:
echo "<ul>";
foreach($rows as $row)
{
echo "<li>$row->value <ul><li>";
echo implode('</li><li>', explode(",", $row->name));
echo "</li></ul></li>";
}
echo "</ul>";