Forum Moderators: coopster

Message Too Old, No Replies

spaces dashes and other things

         

bkeep

8:22 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



I have an issue with a script I am developing. What I have is a database a user can enter in data, so for example they can enter in Rolls Royce for a make and Bentley for a model or Ford for a make and KA Sport for a model.

This is all ok for pulling data the problem has come up recently I have been implementing a SEF link parser and using the make and model to build the links with so I was getting links like /listing/Rolls Royce/Bentley/2/ so what I have done was replace any spaces with a - so the new links look like /listings/Rolls-Royce/Bentley/2/ or /listings/Ford/KA-Sport/1/

Again that worked fine until I posted for help in the Apache forums about the rewrite rules I was using and was told of a few errors in my thought patterns and some duplicate content issues that could arise from the way I was using the redirect patterns, basically I was just using a wildcard for the /make/model/ portion and just grabbing based off of the listing id so I have refactored my code and the new problem has shown its ugly head.

So In the fixing of that I have ran into this issue. I now search the database for the passed $_GET variables make and model so when it searches it is looking up Rolls-Royce or KA-Sport and in the db it is Rolls Royce or KA Sport. I know I can strip out the - and replace it back with a space but what about listings that actually have been entered in with a - so something like Sierra-Denali would then search for Sierra Denali after I strip the -.

I also cannot just force user input to have a - when entered as this is an update and would break older data in users databases.

So is there a way to search for KA-Sport and have it find KA Sport or KA-Sport or maybe another approach I am not thinking of.

Thanks for any help regarding this matter.
Brandon

bkeep

9:29 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



I figured it out instead of using


$_GET = codeClean($_GET);
$id = (int)$_GET["id"];

if (!empty($id)) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$singleSQL.="id = " . $id . "";
}
if (!empty($_GET["make"])) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$singleSQL.="make = '" . $_GET["make"] . "'";
}
if (!empty($_GET["model"])) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$singleSQL.="model = '" . $_GET["model"] . "'";
}
[/code

I used this and it works
[code]
$_GET = codeClean($_GET);
$id = (int)$_GET["id"];

if (!empty($id)) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$singleSQL.="id = " . $id . "";
}
if (!empty($_GET["make"])) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$singleSQL.="make LIKE '" . $_GET["make"] . "'";
}
if (!empty($_GET["model"])) {
if (!empty($singleSQL))
$singleSQL.=" AND ";
$_GET["model"] = str_replace('-', '_', $_GET["model"]);
$singleSQL.="model LIKE '" . $_GET["model"] . "'";
}