Welcome Guest, Not a member yet? Register   Sign In
I need to get unstuck with a problem. Will you help? :(
#1

[eluser]Kinsbane[/eluser]
Hi folks,

I have a project that involves listing a bunch of records from a database. People can make a selection from one of the following: solution, technology, category, and make. I had originally grabbed all the unique types of each of these from the database and put them in a <select> box, like so:
Code:
&lt;select name="" onchange="[removed]=this.options[selectedIndex].value"&gt;
<option value="http://www.site.com/browse/make/make1">Make 1</option>
<option value="http://www.site.com/browse/make/make2">Make 2</option>
...
</select>

However, this is very limiting as it allows to only browse by make, category, technology or solution at a time. What I need is to allow users to make a choice between 1 or all of the different types they can browse by. But what I also need is when the form is submitted, the URL needs to show their selections, so they know they can link to those browsing results again.

Ex: http://www.site.com/browse/technology/category
Ex: http://www.site.com/browse/make
Ex: http://www.site.com/browse/category/

I know CI only does forms via post, so I'm wondering how I can go forward with this.

Should I just make the index() function in the browse controller accept up to four arguments, and then query the database with four different clauses with different combinations?

I'm betting that this is yet again one of those things I'm overthinking to the point where the simplest solution escapes me. Sad
#2

[eluser]Michael Wales[/eluser]
Rather than using different segments for your options, use one segment for all of the current options. Something like:
www.domain.com/browse/technology,category

Then, within in the index() controller, explode the parameter to get an array of selected categories.
#3

[eluser]tonanbarbarian[/eluser]
Except you will need to use something apart from , to seperate the segments as the comma is reserved and not allowed in CI urls
I suggest trying a colon : instead
#4

[eluser]Kinsbane[/eluser]
See what I mean?!

I *WAS* overthinking the process!

Thanks for the help guys, now my headache went away LOL!

Edit:

After thinking about it some more, I still have no idea how to get their selections to show up in the URL with a POST'ed form.

I suppose I could take the POST'ed form selections, capture them in a function, and then perform a redirect() with their POST'ed selections in the URL then which is passed to the proper controller, right?

Sorta like how when you search here on the forums, you have that screen that says, "Please wait while we gather your search results..."
#5

[eluser]sandwormusmc[/eluser]
The problem with showing your users the URL of their search parameters is it's gonna get messy for more than 4 types of search categories. As long as it stays at 4, you should be (somewhat) okay. I saw somewhat because http://whatever/browse/a_b_c_d still looks a bit unwieldy to a user.

Maybe instead you can give your users an option of saving searches they will often use, storing in a database, then loading those preferred searches upon login? (create a user->search table, then load those results when they load a specific URL)?
#6

[eluser]Kinsbane[/eluser]
I was really just looking for an easy way for users to link to what is a logical page - a page containing either all of the documents within /make/technology

or all docs within /make/category

or all docs within /category, /technology, /make, /solution

My only issue is that doing a list of all different makes / categories / etc is a bulleted list for those gets too long, so the select element is perfect for that.

Most users dont need to remember what it says in the URL for browsing this way, they just need to be able to save the URL as a pointer to these docs, and it's not efficient for us to serve up documents only one browsing argument at a time - whether category, technology, make, or solution. I need to provide a solid link for as little as no arguments, or as many as all four.

But I also need to make sure that the order does not matter, and that my system can take the four arguments in any order and be able to serve up correct results from the database.

This system also does not require people to login and with dynamic IP's and the like keeping track of search or browse URL's would get messy as my hardware probably isn't beefy enough to handle those kind of MySQL transactions.

This sucks Sad
#7

[eluser]Michael Wales[/eluser]
I would use URI Routing instead of the _remap magic, but for the sake of having it all in one file easy to understand. You will of course, want to add in a ton of error checking.

Code:
function _remap($method) {
  if ($method == 'form_processor') {
    $this->form_processor();
  } else {
    $this->show_categories();
  }
}

function form_processor() {
  redirect($_POST['form_input']);
}

function show_categories() {
  $category_string = $this->uri->segment(1);
}




Theme © iAndrew 2016 - Forum software by © MyBB