[PHP & Mysql] Not ordered correctly

by 2 replies
3
Hi guys, i have latest mysql version (5.5)

this is the screenshot of groupid field


i didnt touch anything yet, but some cells are not ordered correctly like this


but if i click groupid name in the top, it will ordered correctly like this






below php code output is like first screenshot above, that are not ordered correctly
please help how to make the output ordered correctly, like second screenshot above,
maybe add code like this : order by id asc
but where the right place to put it below?

PHP Code:
$group_ids=explode(" ",$options['groupchoice_ids']);
$groupsql="SELECT id, title FROM " TABLE_PREFIX "thegroup WHERE";
$first=true;
foreach(
$group_ids as $value){
if(!
$first){
$groupsql=$groupsql." OR ";
}
else{
$first=false;
}
$groupsql=$groupsql." id = '".$value."' ";
}

$kh_optionsgroup='<select name = "accounttype">';



$checksec $db->query_read($groupsql);
    if (
$db->num_rows($checksec))
    {
        
        while(
$lboard $db->fetch_array($checksec))
                        {
                        
$kh_optionsgroup=$kh_optionsgroup."<option value ='".$lboard['id']."'>".$lboard['title']."</option>";

                        }                        
    }
$verifystring='$human_verify';
$kh_optionsgroup=$kh_optionsgroup."</select>"
#programming #php
  • Hey mate,

    Throw it in after your loop, eg.

    ....
    $groupsql=$groupsql." id = '".$value."' ";
    }

    $groupsql.=' order by id asc';

    $kh_optionsgroup='<select name = "accounttype">';
    ....

    Cheers,
    Michael
    • [1] reply
    • (or "order by groupid", since that seems to be how you want it ordered)

Next Topics on Trending Feed