cgm225 Posted July 20, 2008 Share Posted July 20, 2008 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? Link to comment https://forums.phpfreaks.com/topic/115651-number-displayed-code-snippet-looking-to-make-more-generic/ Share on other sites More sharing options...
JasonLewis Posted July 20, 2008 Share Posted July 20, 2008 Well, you could store an array in a session that is called "display_options". Like so.. $_SESSION['display_options'] = array("numberDisplayForGallery" => 5, "numberDisplayForBlog" => ; etc etc. Link to comment https://forums.phpfreaks.com/topic/115651-number-displayed-code-snippet-looking-to-make-more-generic/#findComment-594528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.