Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Posts
    292

    [PHP & Mysql] Not ordered correctly

    Hi guys, i have latest mysql version (5.5)

    this is the screenshot of groupid field
    http://freakimage.com/images/148g.jpg

    i didnt touch anything yet, but some cells are not ordered correctly like this
    100
    101
    1000
    136
    but if i click groupid name in the top, it will ordered correctly like this
    http://freakimage.com/images/652g3.jpg





    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>"

  2. #2
    Put the 'order by' just before this line "$checksec = $db->query_read($groupsql);"

  3. #3
    Join Date
    May 2011
    Location
    Columbus, Ohio
    Posts
    270
    As mentioned, add in the ORDER BY. Additionally, here are some suggested clean up for your code:

    PHP Code:
    $groupsql  'SELECT `id`, `title` FROM `' TABLE_PREFIX 'thegroup` ';
    $groupsql .= 'WHERE `id` IN (' implode','$options['groupchoice_ids'] ) . ') ';
    $groupsql .= 'ORDER BY `id` ASC ';

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

    $checksec $db->query_read$groupsql );

    if ( 
    $db->num_rows$checksec ) ) 

        while( 
    $lboard $db->fetch_array$checksec ) ) 
        {
            
    $kh_optionsgroup .= '<option value ="' .$lboard['id'] . '">' htmlspecialchars$lboard['title'] ). '</option>';
        }
    }
    $verifystring '$human_verify';
    $kh_optionsgroup .= '</select>'
    This signature intentionally left blank.

  4. #4
    on a somewhat related note: sorting items in arrays, I had to combine different queries into one array if certain criteria was met.
    therefore I needed to sort data in the array once it was created.

    here are different items for different tasks. HTH

    array mutlisort (sort one array and then apply that sorting to a second array)- >http://php.net/manual/en/function.array-multisort.php

    usort (sort items in an array) -> http://php.net/manual/en/function.usort.php

Similar Threads

  1. PHP/MySQL Syntax not working correctly....
    By kdjernigan in forum Programming Discussion
    Replies: 3
    Last Post: 07-03-2012, 06:06 PM
  2. PHP code does not display correct time
    By prashant1979 in forum Programming Discussion
    Replies: 4
    Last Post: 06-30-2010, 05:41 AM
  3. php environment variables not showing correct value
    By lobaloba9 in forum Programming Discussion
    Replies: 3
    Last Post: 08-02-2004, 04:00 PM
  4. Mysql not working correctly
    By Lyric in forum Web Hosting
    Replies: 9
    Last Post: 09-14-2003, 10:33 AM
  5. Replies: 3
    Last Post: 12-22-2002, 02:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •