Welcome Guest, Not a member yet? Register   Sign In
Pagination.. using multiple segment variables
#1

[eluser]Drayen[/eluser]
Hey guys, kind of a dumb question here.

Three types of fruit:

Orange,Cherry,Apple

mysite.com/cherry/5

That's how the uri segments would set up, so everything works fine

but how would I program the controller to display ALL types of fruit?

mysite.com/all/5

would not return any results, so is there a way to do an if statement where if the uri segment equals something specific it does something, or is there an easy way to automate this? Obviously the way I have it now, it uses the uri segment variable to access the database, but if there's no variable there it will break the pagination.

Thanks for any help, sorry If I worded this poorly.
#2

[eluser]@li[/eluser]
In mysite.com/cherry/5, is 'cherry' the name of a controller or a function, or are you routing it to your default controller?
#3

[eluser]Drayen[/eluser]
[quote author="@li" date="1223819438"]In mysite.com/cherry/5, is 'cherry' the name of a controller or a function, or are you routing it to your default controller?[/quote]

I just skipped all the other stuff, cherry isn't a controller or a function, it's just a variable

mysite.com/index.php?/controller/cherry/5

That would be the full url
#4

[eluser]@li[/eluser]
Well, then I don't understand your question fully. You want to display everything if the variable says all, right? So why don't you just do:

Code:
$option=$this->uri->segment(2);
if ($option=='all')
   $sql='SELECT * FROM table';
else
   $sql="SELECT * FROM table WHERE field='$option';
#5

[eluser]Drayen[/eluser]
[quote author="@li" date="1223851737"]Well, then I don't understand your question fully. You want to display everything if the variable says all, right? So why don't you just do:

Code:
$option=$this->uri->segment(2);
if ($option=='all')
   $sql='SELECT * FROM table';
else
   $sql="SELECT * FROM table WHERE field='$option';
[/quote]

That's what I was looking for, thanks
#6

[eluser]@li[/eluser]
Np. By the way you should still validate the option before putting it inside a query. Something like:

Code:
if ($option !='cherry' && $option !='banana' && $option !='all')
   die('Invalid option given');
else
  $option=mysql_real_escape_string($option);

if ($option=='all')
..............
#7

[eluser]Drayen[/eluser]
[quote author="@li" date="1223852914"]Np. By the way you should still validate the option before putting it inside a query. Something like:

Code:
if ($option !='cherry' && $option !='banana' && $option !='all')
   die('Invalid option given');
else
  $option=mysql_real_escape_string($option);

if ($option=='all')
..............
[/quote]

Ah good idea, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB