php-general Digest 22 May 2005 15:01:31 -0000 Issue 3469
Topics (messages 215710 through 215713):
Re: Search problem
215710 by: Rory Browne
215711 by: Richard Lynch
Re: SMarty and commercial php (a little 0t)
215712 by: M Saleh EG
Re: __get() not reentrant?
215713 by: Jochem Maas
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On 5/21/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to build up a search module for a shop. If I make a basic search
> (product title for example) it is ok.
>
> $query = "SELECT product_id FROM products WHERE title LIKE '%$title%'";
>
> But i need an advance search for more than one field (title, description,
> price, weight)
> The problem is that i don't know which field is filled in by the user (title,
> description, price or weight)
Without error checking, or security code(ie supplied code contains SQL
injection vulnerability):
$sql = "SELECT product_id FROM products WHERE ";
if($_GET['title']){
$sql_ext[] = "title like '%{$_GET['title']}%' ";
}
if($_GET['description']){
$sql_ext[] = "description like '%{$_GET['description']}%' ";
}
$sql .= implode(" OR ", $sql_ext );
> I mean, the user can fill in all fields, or only price field, or title and
> weight etc
>
> How can i do the search?
>
> Thanks
>
>
--- End Message ---
--- Begin Message ---
On Sat, May 21, 2005 1:35 pm, [EMAIL PROTECTED] said:
> I need to build up a search module for a shop. If I make a basic search
> (product title for example) it is ok.
>
> $query = "SELECT product_id FROM products WHERE title LIKE '%$title%'";
>
> But i need an advance search for more than one field (title, description,
> price, weight)
> The problem is that i don't know which field is filled in by the user
> (title, description, price or weight)
> I mean, the user can fill in all fields, or only price field, or title and
> weight etc
You can use http://php.net/strlen to determine if the user has typed
anything into any given INPUT.
Or, if you want a "simple" search with only one INPUT, something like:
$query = "select product_id from products where 1 = 0 ";
$words = explode(' ', $input);
while (list(, $word) = each($words)){
$query .= " or title like '%$word%' ";
$query .= " or description like '%$word%' ";
.
.
.
}
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
I'd recommand you to use the HTML_TEMPLATE_IT. It's a PEAR class for
templating; I've personaly worked on it for building skinnable applications
in which users and admins can change the look of the pages. Bottom line,
it's a PEAR library/extension so no hastle since most of the hosts include
it in their PHP installations. This template does alot of handy jobs such as
nested blocks templating and rendering. However, it does not have the bells
and the whistles of Smarty. Simply it does the job, it's efficient, and very
elegant since your HTML templates would have only 2 extra stuff. One which
is the HTML style comments to define and close blocks and the, Two which is
the variable names to be placed whithin curly braces. So templating does not
realy have a language in IT it's just a ditributed method of writing HTML
and feeding data which forms another Tier in your application not another
Application by itself.
Benefits you'll get by using this PEAR library/extension is that you
wouldnt need to tutor the designers on how to use a procedural markup
templating language hence more flexibility and shorter learning curve. And
plus it does not need no configuration and you could write your own nice
wrapper classes to do special things for you, such as rendering pages
templates, or blockwise template files with predefined variable to be
inserted in the template files.... simple as that. e.g. you could write a
function or a class method to route template files and then only pass them
an array and the function would do the whole thing from rendering to
displaying..... especialy if you use the Web Standards and Semantic Design
skinning would mean only switching CSSs and slight changes in your
structural markup(template files).
Note: If by any change your ISP/Host does not have the PEAR package
installed you could just put it in a directory and simply append it to your
include_dir directive so that you could include/require the class file (only
1 file is the whole package) directly w/o routing to its location.
I'd honestly never implement Smarty for an application I'd work alone on
and then give it up to designers.... I'd use Smarty while working with team
mates of the same range of understanding of the Web Dev/ Design in a team
environment for better performance and that's only if the application
screens are more than 100 and the administration.
HTH.
M.Saleh.E.G
97150-4779817
--- End Message ---
--- Begin Message ---
Christopher J. Bottaro wrote:
Maybe I'm using "reentrant" incorrectly, but here is what I mean...
class Test {
function __get($nm) {
if ($nm == 'x')
return $this->func();
elseif ($nm == 'y')
return 'y';
elseif ($nm == 'xx')
return 'x';
}
function func() {
return $this->xx;
}
}
$t = new Test();
print $t->y . "\n";
print $t->xx . "\n";
print $t->x . "\n";
print $t->func() . "\n";
I would expect the following code to output:
y
x
x
x
But instead, it outputs:
y
x
x
Is this a bug? This limitation is not documented (maybe it should be?).
its not a bug, I believe its documented somewhere how this works.
bottom line __get() does not work from 'inside' the class/object,
so do something like instead:
function func() {
return $this->__get('xx');
}
which may not please the soul, but does work ;-)
-- C
--- End Message ---