Solved

Multiple Criteria Search

Posted on 2013-05-23
3
260 Views
Last Modified: 2013-05-23
I have a table that includes Street, City, State.  If I have a searchbox on a website thats asks for Street, City, State in this format seperated by commas, how do I extract the three values to search the table?
0
Comment
Question by:DS928
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Mark Brady earned 500 total points
ID: 39192615
Very easy to do with php. Assuming your form will post that csv (comma separated values) to the script you would do this. I am assuming you already have a database connection open before running my code (else the mysql_real_escape_string() part won't work)

<?php

$address = isset($_POST['address']) ? $_POST['address'] : null;

if (!is_null($address)) {
     // we need to explode them into separate values
     $address = array_map('trim', explode(',' $address));

    // now because you know the order of them you can pick them out like this

    $street = mysql_real_escape_string($address[0]);
    $city = mysql_real_escape_string($address[1]);
    $state = mysql_real_escape_string($address[2]);

// now you can insert them into your database safely

}

?>

Open in new window

0
 

Author Closing Comment

by:DS928
ID: 39192694
Thank you very much!  I was sweating bullets there for a moment!
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 39193210
You're welcome
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question