You are here: Re: need to do a string replace of "asc" to "desc" or "desc" to "asc" first occurrence only « PHP Programming Language « IT news, forums, messages
Re: need to do a string replace of "asc" to "desc" or "desc" to "asc" first occurrence only

Posted by comp.lang.php on 02/05/06 02:05

Much thanx! That worked!!

Of course, I did a slight variation:

$tmp[1] = 'desc' . substr($tmp[1], 3);

Phil

Justin Koivisto wrote:
> comp.lang.php wrote:
> >
> > Ok using your function:
> >
> > [PHP]
> > if (!function_exists('change_first_order_flag')) {
> > function change_first_order_flag($orderBy){
> > $tmp = explode('__SPLIT__HERE__', preg_replace('`(asc|desc)`i',
> > '__SPLIT__HERE__$1', $orderBy));
> > if (count($tmp) > 1) {
> > // there are at least 2 elements
> > // therefore, it was in there at least once
> > if (substr(strtolower($tmp[1]), 0, 3) == 'des') { // it was in
> > descending order
> > $tmp[1] = 'as' . substr($tmp[1], 3);
> > } else { // it was in ascending order
> > $tmp[1] = 'des' . substr($tmp[1], 3);
> > }
> > }
> > return join($tmp);
> > }
> > }
> >
> > [/PHP]
> >
> > Produced the following MySQL query syntax error:
> >
> > [quote]
> > Fatal error: You have an error in your SQL syntax; check the manual
> > that corresponds to your MySQL server version for the right syntax to
> > use near 'des, upper(s.student_firs' at line 1 using query:
> > [/quote]
> >
> > I'll keep looking at it but apparently it chops the ORDER BY clause
> > incorrectly if the original ORDER BY clause contains ".. asc"
> >
> > Phil
>
> Change:
> $tmp[1] = 'des' . substr($tmp[1], 3);
>
> To:
> $tmp[1] = 'des' . substr($tmp[1], 2);
>
> That should do it... I was in a hurry to get out of the office, so i
> didn't test it.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация