Categories
Development

PHP multi word search

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.

Categories
Movies

LOST Promo Contest

At work every morning after a new episode of LOST airs we all gather near my desk and discuss what we thought of the previous nights episode of LOST. It’s actually pretty fun, and quite funny just how involved we have all gotten with the show.

Recently we heard of a fan promo contest to create a 35 second commercial for the upcoming finale. So a group of us decided why not?

We reviewed the official rules, and viewed what had already been submitted. I then printed out some storyboards for us to fill out with our ideas. We all had some great ideas, but they all seemed to have one connection, and that was how this show has brought so many different people like our office together.

Working on this was a lot of fun. I got to work with people I never work directly with, but happen to work a few feet from. We spent just a little bit of time on it, but think it turned out pretty nice.

Categories
Adventure

Eating with half a numb face

I had an dental appointment to replace a filling for a crack I had in a molar that was done when I was in high school. Going to the dentist was never too bad for me, and I was pretty much in and out in under 45 minutes (way to go Dr. Josh).

However, what I wasn’t expecting was for half of my face to be numb for 4 hours. I half to admit, it’s a very strange feeling. Eating pizza a little bit afterwards turned into quite the epic adventure.

I’ve been known to be a little too rough at times, so I was extremely cautious to make sure I wasn’t accidentally biting into the right side of my cheek while eating. Small bites that were only being chewed on the left side of my mouth was the recipe for success.

2 slices felt like 4, with only half of my jaw doing any substantial work. All in all the whole numbing thing has turned out to be a pretty interesting experience.

Categories
Adventure Sports

Failed Curling Attempt

After watching the 2006 Winter Olympics the Shepherd and I declared that we wanted to play curling after watching much of it on TV that year. Well apparently we had forgotten our mission until 4 years later when the 2010 Winter Olympics came around.

After some brief research we found that the Philadelphia Curling Club was offering a $5 donation class today. So this had to be attended by us.

The Shepherd actually called me at 9:55 AM this morning ready to go. This may not seem early to most, but by his current standards this was an amazing feat and probably summed up just how excited both of us were to finally experience this grand sport.

The ride over took about an hour and a half. We didn’t take a signal wrong turn, which even with GPS we were both proud of.

Upon arriving, we soon discovered that we weren’t the only ones interested in trying out curling. I’d say there was probably 1500-2000 people waiting in a wrapping line outside in the cold with hopes of getting inside to curl.

We waited a good while, with the line barely moving at all. We later found out that there was no chance that we would have an opportunity to curl on this day. Truly tragic news indeed. With our dreams shattered we then decided to get a bite to eat and do something else nearby.

Apparently there isn’t much else to do nearby the curling place. We also somehow took about 4 hours to get back home due to a GPS device that decided to toy with us the remainder of he afternoon. While it was clearly a failed mission, I’m glad we at least followed through with our original plan 4 years ago and gave it a shot. Who knew curling would be this popular.

Categories
Books

Learning Joomla! 1.5 Extension Development

If you’re looking to create extensions for Joomla! 1.5 then you should really check out Learning Joomla! 1.5 Extension Development. I had a project that required a custom component to be created, and the online documentation wasn’t really as good as I’d of liked it to of been.

So I went looking to see if any books had been published recently on extension development. Learning Joomla! 1.5 Extension Development got some decent review online, and I was really stumped with creating my component. So a copy was ordered.

The book does an excellent job of building an extension that makes use of most of the features that would be found in a typical extension. Covering, components, modules, as well as plugins.

With it’s focus on MVC practices, this at first seemed like overkill to me, but once all the features were piling up, it really paid off.

The chapters on creating the admin end of a component were extremely valuable to me. My client now has an easy to use custom component that makes use of the Joomla! admin interface for a seemless CMS experience.

Categories
Development

‘corePHP’ WordPress MU

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.