I was building a search for a site I was working on and needed the search to work on the words a user might type in separately not as one string. For instance, if they typed: “wiffle ball in Louisville”, it would search: wiffle, ball, and Louisville.
Building my SELECT statement was a little tricky at first.
First I had to take my string that’s being passed and store each word in an array. The below is a very simple example, I highly recommend that you clean up the string first!
$searchString = $_POST['who-search'];
$searchArray = explode(" ", $searchString);
This takes our string and uses the explode function to break up our string into an array whenever whitespace is found. Again, this should be refined a bit more in a production level product.
Now that we have an array of the words that were entered, a way to work this array into the SQL statement had to be figured out. Using a couple of loops to go through the array and create OR’s did the job.
$sql = "SELECT DISTINCT * FROM table WHERE (";
while (list($key,$val) = each($searchArray)) {
$val = addslashes($val);
if ($val<>" " and strlen($val) > 0) {
$sql .= "column1 LIKE '%$val%' OR column2 LIKE '%$val%' OR column3 LIKE '%$val%') OR";
}
}
$sql = substr($sql,0,(strLen($sql)-3));//this will eat the last OR
$sql .= ") ORDER BY column1 DESC";
The while loop goes through our array the addslashes function is called to the current value. This escapes apostrophes from throwing off the SQL statement.
If the current value isn’t empty then it’s inserted in the SQL and it’s value compared to the columns you want to compare it against in your SQL. In my example above I’ve used LIKE against 3 columns.
Finally you have to remove the final OR from the SQL statement. A simple substr function is used to remove it from the end.
Just installed and am in the process of configuring the ‘corePHP’ WordPress MU component for Joomla! This nifty component allows a WordPress MU install to run within a Joomla! install.
This is great, you can have a great Joomla! based site that also hosts multiple user WordPress blogs. This is pretty much exactly with these folks were looking for, and it integrates very well with the built in user management as well.
I’m still tinkering with many customizations to get this just how we need it, but most of the difficult work is already done by the component.
Also very convenient are the modules that ‘corePHP’ makes available for this component too. There’s module to display recent blogs, recent posts, etc.
Very good stuff so far.
I downloaded and installed the GCalendar Joomla! component, and am very impressed thus far with it. I’m a big fan and think that Google Calendar is the best calendering system around, especially with some of their sharing features.
While Joomla! does have some very impressive calendar components available, I was really hoping to include a Google Calendar and this component makes it fairly easy to do just that.
If you already have a Google Calendar, installation and setup of the component is a breeze. It currently offers a custom calendar display or you can embed the standard Google Calendar display into your site as well. It’s great, you get the features of a Google Calendar and the integration with a Joomla! site. Very impressive.
While in the process of working on some nifty mapping stuff, I wanted to produce some KML data that I could overlay onto a Google Map. I’m so glad that Google My Maps will allow you to easily export your polygons as a KML file.
So easy, just go to Google Maps, go to My Maps and then create a new map. Then use their super easy marker and polygon tools. The polygon tool works like a very primitive pen tool, but is good enough to draw most buildings on a map.
When you’re ready to export what you’ve drawn on your map as KML just click on the View in Google Earth link and it should produce a nice KML file for you.
I’ve always been a fan of the Webmaster Tools that Google offers. If you have a website, you really should make use of some of the really nice features that they offer. The crawling and indexing information found there is great.
In early December they added some new features, with the Site Performance feature being one of the more useful upgrades I’ve found in a while. It can be found under the Labs section and shares very useful info about your site’s speed as well as how well or not so well you rank in terms of load times compared with other sites.
As a guy who continually tries to squeeze each and every millisecond out of load times, this is great information to know! They also offer suggestions as to how you can improve the speed of certain pages on your site as well.
While many of these features can also be found in YSlow as well (which is another must for any developer), it also does warrant a look.
Just finished up converting Mullica Hill Skin Care’s site to be powered by Joomla. Their site was a series of basic html files setup in Dreamweaver, and the client had used a Joomla powered site in the past and wanted this site to be powered by Joomla as well.
Joomla is an open source CMS (content management system). It’s pretty awesome and has been an excellent solution for many people I’ve worked with.
The site’s design stayed the same, with barely any changes made to the existing markup with the change over. We’ve also included a blog for the client to use too.
“Let me just say thanks again for converting the site so quickly…it’s so much easier to use!!!:)”
There’s some amazing tools available now for site owners, and it’s always great when I can set them up with the right tools to make their lives easier while at the same time having a current site.