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