Jump to content

Recommended Posts

Hey guys i need to sort by title asc articles in a french website. The problem i am facing is that the titles are HTML encoded before they're added to the database. Some foreign special characters are causing the SQL order by argument not usable.

 

Ex: É is encoded to É

 

The order by only sees the first character & and places that article on top instead on sorting them with the E ...

 

So this is what i tryed as an alternat methode to the sql sorting but it's obviously not working ...

 

$select = mysql_query("SELECT * FROM $table where semaine!='0' and publier = '1'  limit $offset,$nombre_par_page") or die(mysql_error());
$page = mysql_fetch_array($select);

foreach ($page as $value){
    $value=html_entity_decode($value);
}

$page = sort($value);

while ($page) {
// The SQL result loop
echo "$page[titre]<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/178231-solved-sort-help-needed/
Share on other sites

I tryed this

 

SELECT * FROM page where semaine!='0' and publier = '1' order by REPLACE('&#201;','E', REPLACE('&#233;','e', REPLACE('&#200;','E', REPLACE('&#232;','e', REPLACE('&#192;','A', REPLACE('&#224;','a', REPLACE('&#202;','E', REPLACE('&#234;','e', REPLACE('&#206;','I', REPLACE('&#238;','i', REPLACE('&#199;','C', REPLACE('&#231;','c', REPLACE('&#207;','I', REPLACE('&#239;','i', REPLACE('&#219;','U', REPLACE('&#251;','u', REPLACE('&#217;','u', REPLACE('&#249;','u', titre)))))))))))))))))) asc limit 0,10

 

But that did not work as well ...

Found a work arround

 

This is what i did:

SELECT * , replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( 
replace( titre, 'É', 'E' ) , 
'é', 'e' ) , 
'È', 'E' ) , 
'è', 'e' ) , 
'À', 'A' ) , 
'à', 'a' ) , 
'Ê', 'E' ) , 
'ê', 'e' ) , 
'Î', 'I' ) , 
'î', 'i' ) , 
'Ç', 'C' ) , 
'ç', 'c' ) , 
'Ï', 'I' ) , 
'ï', 'i' ) , 
'Û', 'U' ) , 
'û', 'u' ) , 
'Ù', 'U' ) , 
'ù', 'u' ) AS tt
FROM page
ORDER BY tt ASC 
LIMIT 0 , 10

 

Hope that helps somebody else in the future ;-)

Cheers

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.