How do I organize an array that is an html line containing variables pulled from mysql table?
I am attempting to alphabetically organize an options list populated from an array; the problem is that the array array contains html tags at t开发者_JS百科he front so sorting it seems imposable. I have tried 'ORDER BY' in the mysql query from which the array variables are pulled, but the command gets lost.
The whole system seems hardwired to sort the list by the key column in the mysql table, which is simply not acceptable. Is there any way around this issue? Any help would be VERY appreciated!
Here is an example of what I'm trying to do:
$options = array();
$query1=mysql_query("Select * From table1 Where name='blah'");
while($queryvalue1=mysql_fetch_array($query1)) {
$array1 = $queryvalue1['Column1'];
$query2=mysql_query("Select * From table2 Where id In ($array1) Order by value DESC");
while($queryvalue2=mysql_fetch_array($query2)) {
$var1 = $queryvalue2['Column2'];
$var2 = $queryvalue2['Column3'];
$options[] = "<option value='$var'>$var2</option>"
}
}
$options = implode(PHP_EOL, $options);
There's certainly ways to do it, but they are all much slower than letting the database sort for you.
It might not be the simplest solution, but I'd suggest getting rid of the HTML tags and repopulating the database, even if you have to use a temporary table while you fix the rest of your code. Do it right so you don't have to continually work around a serious problem for the rest of the application lifecycle.
精彩评论