Jump to content

Number displayed code snippet... looking to make more generic...


cgm225

Recommended Posts

I have a gallery I coded in which I allow a user to select from a drop down box how many photos they wish to view per page.  I set the number of photos to be displayed with the following snippet:

 

if (empty($_POST["number_displayed"])) {
    $number_displayed = !empty($_SESSION['number_displayed']) ? $_SESSION['number_displayed'] : "4";  //In this case the default number of photos to be displayed would be four
} else {
    $number_displayed = $_POST["number_displayed"];
    $_SESSION['number_displayed'] = $number_displayed;
}

 

So in that snippet, I check if a user has selected a new number to be displayed from the dropdown form, and if so, set it to the $number_displayed variable, and make it a session variable. 

 

However, now I want to add this feature to other applications on my site, like my notes/blog site (i.e. how many entries to display).  Therefore, I want to make this snippet more generic, and possibly a function or class, where I can create specific session variables for any particular app, like, I could create a $numberDisplayForGallery and $numberDisplayForBlog variables with the same code.

 

Any ideas on how to do this the best way?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.