close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Filtering recordset using LIKE failing

Thread began 9/04/2009 2:13 pm by Les Crowley | Last modified 9/08/2009 5:39 pm by Jason Byrnes | 2748 views | 14 replies |

Les CrowleyBeta Tester

Filtering recordset using LIKE failing

I've worked out how to get a checkbox group saved to the db into a single field.

The values in the field are: Seascapes Elvis ZZ Top

This is my recordset and it's using galselect as the parameter that contains the above values.

php:
$_GET['galselect'] = $row_companyid['gallerycategories'];


$colname_prodcats_retail = "-1";
if (isset($_GET['galselect'])) {
  $colname_prodcats_retail = (get_magic_quotes_gpc()) ? $_GET['galselect'] : addslashes($_GET['galselect']);
}
mysql_select_db($database_rockncom, $rockncom);
$query_prodcats_retail = sprintf("SELECT DISTINCT Category FROM products WHERE Category LIKE %s ORDER BY Category ASC", GetSQLValueString($colname_prodcats_retail . "%", "text"));
$prodcats_retail = mysql_query($query_prodcats_retail, $rockncom) or die(mysql_error());
$row_prodcats_retail = mysql_fetch_assoc($prodcats_retail);



The problem I'm having is that if there is a single value (such as Seascapes) it will return Seascapes from the recordset - it won't return any results if there are multiple words (such as Seascapes Elvis ZZ Top).

Am I missing something in the way the conditional LIKE works?

Any help is greatly appreciated.

Sign in to reply to this post

tom92909Beta Tester

Try %s%


php:
SELECT DISTINCT Category FROM products WHERE Category LIKE %s% ORDER BY Category ASC"
Sign in to reply to this post

Les CrowleyBeta Tester

That gives me the following error.


Warning: sprintf() [function.sprintf]: Too few arguments in C:\wamp\www\rockinCom\index.php on line 97
Query was empty

This may help to clarify a bit - here's the sql from the dreamweaver recordset view. colname is the parameter and I've added % to the end of it. There's no error but it will only return a result if there is only a single word in the parameter.

SELECT DISTINCT Category
FROM products
WHERE Category LIKE colname%
ORDER BY Category ASC

Sign in to reply to this post

tom92909Beta Tester

hmmm that should have worked...

Sprintf might use different syntax than using a straight SELECT statement.

Below works great in PhpMyAdmin ( I just checked to be sure ).

LIKE CONVERT( _utf8 '%s% USING latin1)

Sign in to reply to this post

Les CrowleyBeta Tester

No idea what's causing it to fail. I've also tried it was a comma separating the values and get the exact same results ... no results.

Wondering if it's failing because it's not picking up the individual words and it's trying to match records to the entire value... in this case the value is "Seascapes Elvis ZZ Top" and it returns nothing.

If I only have Seascapes it returns Seascapes.

I would think even with the value of "Seascapes Elvis ZZ Top" it would return any record that has any of those words in it.. unless I'm misunderstanding how LIKE works. Or do I have to add something else to make this work?

Sign in to reply to this post

Jason ByrnesWebAssist

try:

php:
SELECT DISTINCT Category FROM products WHERE Category LIKE %s'%' ORDER BY Category ASC"
Sign in to reply to this post

Les CrowleyBeta Tester

That returns an error also
Warning: sprintf() [function.sprintf]: Too few arguments in C:\wamp\www\rockinCom\index.php on line 97
Query was empty

Sign in to reply to this post

CraigRBeta Tester

working example with url parameter

try this, hope it works...

$colname_Recordset1 = "-1";
if (isset($_GET['o'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['o'] : addslashes($_GET['o']);
}
mysql_select_db($database_connection, $connection);
$query_Recordset1 = sprintf("SELECT * FROM tblcategory WHERE `Description` LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Sign in to reply to this post

Les CrowleyBeta Tester

Hi Craig,

Same results. Recordset returns nothing but there is no error. Thanks for trying.

Still wondering if it's failing because it's not picking up the individual words and it's trying to match records to the entire value... in this case the value is "Seascapes Elvis ZZ Top" and because there's nothing in the recordset that matches all three words it returns nothing.

Sign in to reply to this post

anonymous

Craig,

I recently had a similar issue... the only way I have been able to get it to work when trying to query like you are is to first store that recordset as a variable because you need the percentage sign for the like variable - but since it is part of the variable in the method you are using, it will result in an error.

So the way to stop the error is to rewrite the query like this:

php:
$valuetocheck = $colname_Recordset1;


mysql_select_db($database_connection, $connection);
$query_Recordset1 = sprintf("SELECT * FROM tblcategory WHERE `Description` LIKE '%$valuetocheck%' ";
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);



Cheers,

Brian

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...