Jump to content

[SOLVED] order


drisate

Recommended Posts

Hey guys ... how do you order by something but keep something else first ...

 

select * from table order by ORDER BY MUN_CODE like = '66057', MUN_CODE

 

I know the querry is not working it's just an exemple. In this case you order by MUN_CODE but you keep the 66057 on top

 

Link to comment
Share on other sites

Oh wow lol looks complicated ... my querry is already knid of big how do you adapte that to this?

 

<?php  
$sql = "SELECT * FROM inscriptions WHERE (AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440' OR AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440') ";

if(isset($_GET['MUN_CODE'])){
$sql = $sql . " and MUN_CODE='".$_GET['MUN_CODE']."'";
}
if(isset($_GET['GENRE_PROPRIETE'])){
$sql = $sql . " and GENRE_PROPRIETE='".$_GET['GENRE_PROPRIETE']."'";
}

if(!isset($_GET['MUN_CODE']) && !isset($_GET['GENRE_PROPRIETE']) && !isset($_GET['prix'])){
$sql = $sql . " ORDER BY MUN_CODE LIMIT $debut,$combienparpage;";
}
echo $sql;
$sql = mysql_query($sql);
?>

 

the above gives

 

SELECT * FROM inscriptions WHERE (AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440' OR AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440') ORDER BY MUN_CODE LIMIT 0,10;

 

I wana keep the rows wher MUN_CODE='66057' on top

 

i tryed this but it's returning no results

 

SELECT *,(CASE SUBSTR(MUN_CODE,1,1) WHEN '66057' THEN 0 ELSE 1 END) as sorter FROM inscriptions WHERE (AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440' OR AGENT_INSCRIPTEUR_1='MT76440' OR AGENT_INSCRIPTEUR_2='MT76440') ORDER BY as sorter, MUN_CODE LIMIT 0,10;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.