Results 1 to 4 of 4
-
05-03-2015, 09:09 PM #1Web Hosting Guru
- 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
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>";
-
05-04-2015, 07:17 PM #2Newbie
- Join Date
- Mar 2015
- Posts
- 11
Put the 'order by' just before this line "$checksec = $db->query_read($groupsql);"
-
05-06-2015, 07:19 AM #3Web Hosting Guru
- 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.
-
05-22-2015, 10:07 AM #4Newbie
- Join Date
- Nov 2013
- Posts
- 28
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
-
PHP/MySQL Syntax not working correctly....
By kdjernigan in forum Programming DiscussionReplies: 3Last Post: 07-03-2012, 06:06 PM -
PHP code does not display correct time
By prashant1979 in forum Programming DiscussionReplies: 4Last Post: 06-30-2010, 05:41 AM -
php environment variables not showing correct value
By lobaloba9 in forum Programming DiscussionReplies: 3Last Post: 08-02-2004, 04:00 PM -
Mysql not working correctly
By Lyric in forum Web HostingReplies: 9Last Post: 09-14-2003, 10:33 AM -
Simple problem with PHP and MySQL not populating corectly some of my forms...
By adlep in forum Programming DiscussionReplies: 3Last Post: 12-22-2002, 02:34 PM