Reply to Re: help with str_replace in select statement

Your name:

Reply:


Posted by salmobytes on 09/06/07 12:38

On Sep 6, 6:03 am, 4sgcv5hy6d0r <fj4sgcv5hy6d...@temporaryinbox.com>
wrote:
> Hi group!
> Why str_replace does not work in this case?
> Thanks in advance!
>
> if ($cat0 != ''){ $query_cat0 = "cat0 LIKE '$cat0%'"; }
> if ($cat1 != ''){ $query_cat1 = "AND cat1 LIKE '$cat1%'"; }
> if ($cat2 != ''){ $query_cat2 = "AND cat2 LIKE '$cat2%'"; }
>
> $mysql_query = "SELECT * FROM mytable WHERE ".$query_cat0." ".
> $query_cat1." ".$query_cat2;
> $what = 'WHERE AND';
> $with = 'WHERE';
>
> $mysql_query = str_replace($what, $with, $mysql_query);
>
> echo $mysql_query;

It doesn't work?
If you put 'AND ' in front
of cat0 you could mix the where conditions in arbitrary
runtime combinations and order sequences.

.....keep two buffers and a table-name hash:

$select = 'select '; // append column titles according to menu
clicks
$from = ''; // foreach column title in select, insert
matching table name to a hash
where = ' where ' // foreach column title, take a condition from
menu values
.....put it all together and (as you suggest) turn 'where and' into
'where'

[Back to original 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

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