Re: [PHP-DB] how to do query on partial field contents ???

2004-02-24 Thread Frank Flynn
Too true - this is why a page that I promised would only take a few minutes
winds up taking all week.

But it makes steady employment for the QA team...

Frank 

On 2/24/04 10:37 AM, "Andy Armstrong" <[EMAIL PROTECTED]> wrote:

> Frank Flynn wrote:
> 
>> And if you'd like to make wild carding optional keep your code the way it
>> is:
>> 
>> $query .= " AND `model` LIKE '".$_GET['search']."'";
>> 
>> And put a comment on the web page "Use the % for wild cards".
>> 
>> The thing about:
>>   $query .= " AND `model` LIKE '%".$_GET['search']."%'";
>> 
>> Is it will return many results if $_GET['search'] is very small like one
>> letter.
> 
> And bear in mind that there's could be a nasty SQL injection problem
> with that code if $_GET['search'] hasn't been SQL escaped in some way.


-- 
Frank Flynn
Poet, Artist & Mystic


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



Re: [PHP-DB] how to do query on partial field contents ???

2004-02-24 Thread Andy Armstrong
Frank Flynn wrote:

And if you'd like to make wild carding optional keep your code the way it
is:
$query .= " AND `model` LIKE '".$_GET['search']."'";

And put a comment on the web page "Use the % for wild cards".

The thing about:
  $query .= " AND `model` LIKE '%".$_GET['search']."%'";
Is it will return many results if $_GET['search'] is very small like one
letter.
And bear in mind that there's could be a nasty SQL injection problem 
with that code if $_GET['search'] hasn't been SQL escaped in some way.

--
Andy Armstrong, Tagish
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] how to do query on partial field contents ???

2004-02-24 Thread Frank Flynn
And if you'd like to make wild carding optional keep your code the way it
is:

$query .= " AND `model` LIKE '".$_GET['search']."'";

And put a comment on the web page "Use the % for wild cards".

The thing about:
  $query .= " AND `model` LIKE '%".$_GET['search']."%'";

Is it will return many results if $_GET['search'] is very small like one
letter.

Good Luck,
Frank


On 2/24/04 8:20 AM, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> From: "Nitin Mehta" <[EMAIL PROTECTED]>
> Date: Tue, 24 Feb 2004 13:18:24 +0530
> To: <[EMAIL PROTECTED]>, "-{ Rene Brehmer }-" <[EMAIL PROTECTED]>
> Subject: Re: [PHP-DB] how to do query on partial field contents ???
> 
> for partial match
> 
> like 'value' doesn't work, use
> like '%value%'
> 
> Hop that helps
> Nitin
> 
> - Original Message -
> From: "-{ Rene Brehmer }-" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, February 24, 2004 11:57 AM
> Subject: [PHP-DB] how to do query on partial field contents ???
> 


-- 
Frank Flynn
Poet, Artist & Mystic

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



Re: [PHP-DB] how to do query on partial field contents ???

2004-02-24 Thread Nitin Mehta
for partial match

like 'value' doesn't work, use
like '%value%'

Hop that helps
Nitin

- Original Message - 
From: "-{ Rene Brehmer }-" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 24, 2004 11:57 AM
Subject: [PHP-DB] how to do query on partial field contents ???


> hi gang
>
> I've mentioned this project before a couple of weeks ago ... just been
busy
> with school, so haven't had time to work on it that much
>
> But anyways ... the test version is running here:
> http://metalbunny.net/computers/cpudb.php
> it's running with debug code, which should be obvious if you test it ...
>
> It's MySQL database ... testes it on both my webhost and my local test
> server, result is the same.
>
> If you fill in the search field and click the search button, I want it to
> list all records where the fields partially matches... but as it is now,
it
> will only list records where the entire field matches. That is, if you
> search for "Athlon", it will only list those where a field exactly is
> "Athlon", whereas I want to list "Athlon", "Athlon XP", "Athlon MP", and
so
> on ...
>
> Figure that it would require some sort of wildcard, but the traditional
> ones I've tried didn't work, so I'm at a dead end once again...
>
> This is the 90 lines of code that generates the queries. Probably room for
> improvement, but then I'm no expert at this:
>
> $query = 'none';
> $basequery = 'SELECT * FROM cpu';
>
> if (isset($_GET['search'])) {
>$query = $basequery.' WHERE cpuID <> 0 ';
>$setorder = true;
>
>$query .= " AND `model` LIKE '".$_GET['search']."'"; // this block
split
> for debug reasons
>$query .= " OR `variant` LIKE '".$_GET['search']."'";
>$query .= " OR `type` like '".$_GET['search']."'";
> }
> else if (isset($_GET['make']) || isset($_GET['model']) ||
> isset($_GET['socket'])) {
>$query = $basequery;
>$setorder = true;
>
>if ($_GET['make'] != 'All' || $_GET['model'] != 'All' ||
$_GET['socket']
> != 'All') {
>  $query .= ' WHERE ';
>  if ($_GET['make'] != 'All') {
>$query .= "`make`='".str_replace('+',' ',$_GET['make'])."'";
>  }
>  if ($_GET['make'] != 'All' && $_GET['model'] != 'All') {
>$query .= ' AND ';
>  }
>  if ($_GET['model'] != 'All') {
>$query .= "`model`='".str_replace('+',' ',$_GET['model'])."'";
>  }
>  if ($_GET['model'] != 'All' && $_GET['socket'] != 'All') {
>$query .= ' AND ';
>  }
>  if ($_GET['socket'] != 'All') {
>$query .= "`socket`='".str_replace('+',' ',$_GET['socket'])."'";
>  }
>}
>
>$linkquery = str_replace('
>
','+','make='.$_GET['make'].'&model='.$_GET['model'].'&socket='.$_GET['socke
t']);
> }
> if ($setorder) {
>switch ($_GET['order']) {
>  case 'socket':
>$query .= ' ORDER BY socket';
>break;
>  case 'form':
>$query .= ' ORDER BY form';
>break;
>  case 'vcache':
>$query .= ' ORDER BY vcache';
>break;
>  case 'vcore':
>$query .= ' ORDER BY vcore';
>break;
>  case 'l2':
>$query .= ' ORDER BY l2';
>break;
>  case 'l1':
>$query .= ' ORDER BY l1';
>break;
>  case 'fsb':
>$query .= ' ORDER BY fsb';
>break;
>  case 'multi':
>$query .= ' ORDER BY multi';
>break;
>  case 'clock':
>$query .= ' ORDER BY clock';
>break;
>  case 'type':
>$query .= ' ORDER BY type';
>break;
>  case 'variant':
>$query .= ' ORDER BY variant';
>break;
>  case 'model':
>$query .= ' ORDER BY model';
>break;
>  case 'make':
>  default:
>$query .= ' ORDER BY make';
>break;
>}
>switch ($_GET['ad']) {
>  case 'd':
>$query .= ' DESC';
>break;
>  case 'a':
>  default:
>$query .= ' ASC';
>break;
>}
> }
>
> The order part is of course not that relevant in this case, but I left it
> in the snip for the variables set in the query part to make sense...
> Question is simple: What do I change in the code to make it do partial
> field matches, instead of complete ???
>
>
> Hoping for help :) ... TIA
>
> Rene
> -- 
> Rene Brehmer
> aka Metalbunny
>
> http://metalbunny.net/
> References, tools, and other useful stuff...
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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