Welcome Guest, Not a member yet? Register   Sign In
Search URL
#1

[eluser]McNoggin[/eluser]
I am using CI to build my website, http://www.flybrushless.com/. The website contains a database of electric motors used in RC airplanes and helicopters.

I am using mod_rewrite so the URLS show as /controller/function/... etc. So far I have implemented a search by manufacturer that works by going to the URL /search/manufacturer/GPS. Where "GPS" is the name of a manufacture you are searching by.

Right now I am working on implementing a way to search 1 or more of the available fields in the database. I would like these searches to be accessable from the URL so that people can easily send/share links to a specific search. The problem is trying to figure out a way to make this work, since the number of parameters and the fields can vary.

My initial thinking was to do something like this
http://www.flybrushless.com/search/advan.../<value2>/....

Where <fieldx> would be replaced with the field name, such as weight, and <valuex> would be replaced with the corresponding value. I was wondering if anyone else has done something similar to this before, or if you have any other ideas on how to do it. My concern with using the above method is if the values contain spaces or any other special chars (I realize I can convert them to and so on).

Thanks,
McNoggin
#2

[eluser]AndrewMalachel[/eluser]
Have you tried these function?
Code:
$advance = $this->uri->uri_to_assoc(3);
that way you can have the search field and value in array..

if your URL is:
Code:
http://www.flybrushless.com/search/advance/manufacturer/GPS/weight/5/volume/20
(considering "search" is your controller (1st URI segment) and "advance" is your controller function (2nd URI segment) )
then you'll get the result as:
Code:
$advance = array
(
    "manufacture" => "GPS",
    "weight" => "5",
    "volume" => "20"
)
if you seek it in database you can use the "foreach()" function on your array ($advance)
with "$this->db->where()" or "$this->db->where_in()" function to extract the result
from your database..

check http://ellislab.com/codeigniter/user-gui...s/uri.html for reference..

hope it helps.. :-)
#3

[eluser]McNoggin[/eluser]
That doesn't just help, its exactly what I was looking for! I was not looking forward to implementing that search, but now its going to be a piece of cake.

Thanks for the help.




Theme © iAndrew 2016 - Forum software by © MyBB