php-general Digest 22 May 2005 15:01:31 -0000 Issue 3469

2005-05-22 Thread php-general-digest-help

php-general Digest 22 May 2005 15:01:31 - 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:
php-general@lists.php.net


--
---BeginMessage---
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---
---BeginMessage---
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---
---BeginMessage---
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 

Re: [PHP] Search problem

2005-05-22 Thread Richard Lynch
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SMarty and commercial php (a little 0t)

2005-05-22 Thread M Saleh EG
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


Re: [PHP] __get() not reentrant?

2005-05-22 Thread Jochem Maas

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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: __get() not reentrant?

2005-05-22 Thread Christopher J. Bottaro
Jochem Maas wrote:

 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 ;-)

Hehe, my soul is hard to please...=P

Actually, __get() does work from inside the class.  In the sample code I
posted, func() does indeed return 'x' when called from main.  It does not
work when called from within a call to __get().  In other words,
$this-attribute does not work if __get() appears anywhere in the call
stack.

Its just a small annoyance.  I use $this-attribute everywhere in the class,
but I have to remember to use $this-__get(attribute) in methods that can
be called from __get().

-- C

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] financial application form

2005-05-22 Thread Dave Sayer
Hi, First post here. 

 

I have a large application form (financial) which I have working fine but I
need to be able to have it either work as a single application or a joint
one. If joint it needs to display two forms for the user to fill in. I am
just wondering how I can do this without having to write a second form as
there are 8 pages (around a hundred fields)  to this form and I dont fancy
modifying all of the vars and fields to do this. If anyone knows how or can
point me in the right direction, id be most thankful.

 

Cheers

 

Dave

 


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.322 / Virus Database: 266.11.15 - Release Date: 22/05/2005
 


Re: [PHP] Re: __get() not reentrant?

2005-05-22 Thread Marek Kilimajer

Christopher J. Bottaro wrote:

Jochem Maas wrote:



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 ;-)



Hehe, my soul is hard to please...=P

Actually, __get() does work from inside the class.  In the sample code I
posted, func() does indeed return 'x' when called from main.  It does not
work when called from within a call to __get().  In other words,
$this-attribute does not work if __get() appears anywhere in the call
stack.

Its just a small annoyance.


I think it would be more annoying if __get() would be recursively called 
to infinity.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Re: __get() not reentrant?

2005-05-22 Thread Christopher J. Bottaro
Marek Kilimajer wrote:

 Christopher J. Bottaro wrote:
 Jochem Maas wrote:
 
 
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 ;-)
 
 
 Hehe, my soul is hard to please...=P
 
 Actually, __get() does work from inside the class.  In the sample code I
 posted, func() does indeed return 'x' when called from main.  It does not
 work when called from within a call to __get().  In other words,
 $this-attribute does not work if __get() appears anywhere in the call
 stack.
 
 Its just a small annoyance.
 
 I think it would be more annoying if __get() would be recursively called
 to infinity.

And what would make it any different from a normal recursive function? 
Every recursive function runs the risk of going into infinite loop if the
programmer doesn't understand the basic concept (or makes a silly mistake). 
Loops run the risk of going on indefinitely as well.  Maybe PHP should
disable all forms of loops/recursion to protect the programmers from
themselves.

Trace my code for $t-x...
$t-x;
$t-__get('x');
$t-func();
$t-xx;
$t-__get('xx');
'x'

What is wrong with that?  Why should PHP disallow that recursive __get()
call?  It is perfectly valid recursive code.  It terminates for all cases.

-- C

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Search problem

2005-05-22 Thread Joe Wollard
I used to search the same way until someone on this list mentioned using 
a fulltext index in mysql. Doing this almost eliminated all my headaches 
with searching.
Easiest way to create a fulltext index is to use phpMyAdmin. Once you've 
created the fulltext index on `title`,`description`,`price`,`weight` you 
can then search all columns (much faster than the other way I might add) 
by using a simply SQL query such as this:


$sql = SELECT * FROM `products` WHERE 
MATCH(`title`,`description`,`price`,`weight`) AGAINST (' . 
mysql_escape_string($_GET['query']) . ');


More on FULLTEXT can be found here: 
http://dev.mysql.com/doc/mysql/en/fulltext-search.html


Hope that helps!
-Joe W.
www.joewollard.com http://www.joewollard.com

[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)
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