Testing one numeric $string against another

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 28, 2011   (RSS)

Re: [Perchpole] Testing one numeric $string against another

By Jason - April 27, 2011

Hi Perch,

From what you're describing, $string1 is the value being stored in the database (ie, what we're comparing against in the WHERE clause) and $string2 is a string we've gotten somewhere else in the PHP code. Does that sound correct?

The quickest way to do this would be to change $string2 into a tab delimited string and then do a straight comparison. for example:

<?php
$string2 = "\t". strreplace(",", "\t", str_replace(" ", "", trim(mysql_escape($string2)))). "\t";
?>


Then, assuming the field in the database is called string1, the WHERE clause would look like this:

'where' => "string1 = '$string2'",

Now, it's important to note that this is a string comparison, so, if the numbers in each string are all the same, but are in a different order, this comparison would fail.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing one numeric $string against another

By Perchpole - April 28, 2011

Hi, Jason -

Thanks for your help - and the code. I will certainly try to implement it next time I need to compare 2 strings.

However, my immediate problem went off at an angle a couple of days ago and became this...

Very Odd WHERE Clause Issue!

I'd appreciate your thoughts.

:0)

Perch