I have an array namely $checked_posts which looks like -
Array
(
[0] => 13
[1] => 15
)
This array contains the id's of the posts which are selected.
I fetch data from database like -
$q=mysql_query("select ID,post_title from sa_posts
where post_author='".$this->session->userdata('admin_id')."'
and post_type='post'
and post_status='publish'
order by ID desc
");
This query fetch id and post_title
I want to compare array $checked_posts value(id) with select queries fetch id
If both match then I want to show that record early, if not then such records should be display after all selected records.
Suppose my $checked_post array contains -
Array
(
[0] => 13
[1] => 15
)
and my select query fetch records(id's) like 15,13,20,25,32 in such conditions I have to display the records firstly where the id matches and later I want to display all unmatched elements.
I have tried so far -
$q=mysql_query("select ID,post_title from sa_posts
where post_author='".$this->session->userdata('admin_id')."'
and post_type='post'
and post_status='publish'
order by ID desc
");
while($p=mysql_fetch_array($q))
{
if(in_array($p['ID'],$checked_posts))
{
$check_post='checked'; // I want to display all these elements firstly and later all unmatched elements.
}
else
{
$check_post='';
}
echo "<li class='menu_post_list' id='".$m_n."' style='list-style:none;display:".$disp_post."'>
<input type='checkbox' value='".$p['ID']."' class='menu_list_post' $check_post> ".$p['post_title']."</li>";
}
Please help me.
Thanks.