close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

search - replace spaces in search with commas

Thread began 7/15/2013 2:16 pm by mrs | Last modified 7/16/2013 11:48 am by Jason Byrnes | 473 views | 5 replies |

mrs

search - replace spaces in search with commas

I need to reduce search results returned, and I am going to have more than one repeated list of search results due to three different recordsets for three different tables in my DB.

I need to replace spaces with commas, but my code isn't working for some reason. By that I mean if I type 'test', I get 93 results. If I type 'test sweden', I still get 93 results... what ever I type, I get 93 results!

This is my replace code:

<?php
// line added to insert commas before spaces which are inputted by the user during searches
if(isset($_GET["searchbox"])) $_GET["searchbox"] = str_replace(" ", ", ", $_GET["searchbox"]);
?>


This is one of the WA search codes:

<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: rs_eventslist;
//Searchpage: search-results.php;
//Form: searchform;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations
$KeyArr0 = array("fld_eventNAME", "fld_eventLOCATION", "fld_eventINTRO", "fld_eventDETAIL", "fld_eventVENUE", "fld_eventMAPTITLE", "fld_eventMAPADDRESS", "fld_eventMAPDESCRIPTION", "fld_eventEMAIL", "fld_eventURL");

//comparison list additions
$WADbSearch1->keywordComparison($KeyArr0,"".((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") ."","AND","Includes",",%20","%20","%22","%22",0);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_searchresults"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_searchresults"]) && $_SESSION["WADbSearch1_searchresults"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_searchresults"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>



This is my search form code:

<form action="search-results.php" id="searchform" name="searchform" method="get">
<input name="searchbox" type="text" id="searchbox" placeholder="Search...">
<input type="image" src="../images/search-trans.png" width="26px" height="26px" border="0" alt="GO" name="button" id="button" value="Button">
</form>

Am I not meant to be using the 'searchbox' to replace the spaces with commas?

Thanks.

Sign in to reply to this post

Jason ByrnesWebAssist

your form is using the get method, but the trigger for the search is looking for a post:

if ((isset($_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {


change that to:
if ((isset($_GET["WADbSearch1"])) && ($_GET["WADbSearch1"] != "")) {

Sign in to reply to this post

mrs

Aha... I missed that bit, however, I did initially have it all set to post. Would get or post make a significant difference?

Also, something that has just popped into my head is that I am using an image as the submit button rather than an actual button. Do I need to address the code in the same way as I would do for inserting to the database. I recall I had to change the trigger code from 'submit' to something like 'x_submit' because it was an image.

I'm still getting the same results... 93 regardless!

I've added the page just in case you need to see it in it's entirety!

Sign in to reply to this post

mrs

This post has been deleted.

mrs

I did have another post which was saying how the search was being ignore because I was trying to insert into a locked region of a template. As it had already worked and I had been getting some results, I didn't believe this to be true. However after releasing the page from the template, I now see that a hidden field has been added. This is the form now:


<form action="search-results.php" id="searchform" name="searchform" method="post">
<input name="searchbox" type="text" id="searchbox" placeholder="Search...">
<input type="image" src="images/search-trans.png" width="26px" height="26px" border="0" alt="GO" name="button" id="button" value="Button">
<input type="hidden" name="WADbSearch1" value="Submit">
</form>


<input type="hidden" name="WADbSearch1" value="Submit"> was added. What is this used for, and is it needed for what I am trying to achieve? Also, just to ask again, should I be using GET or POST for the switching of spaces to commas?

Sign in to reply to this post

Jason ByrnesWebAssist

the WADbSearch1 form element is being used for the trigger.

as for whether to use get or post, it really doesn't matter to much as long as it is consistent.

your current form is set to use POST, so the code for replacing the commas should use the POST collection, your previous form was set to use GET, that is why i suggested converting to the GET collection.

look at the form tag to determine which should be used.

Sign in to reply to this post

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...