I want to keep page in search form and when I visit another page and return to previous to see only what I search.
For example, I have page with table, in that table I have list of all products which is 30 products. When I submit search query for some word and get per instance 5 products, I want to keep that and visit all another pages and when I back on product page to see again only that 5 products.
Any help?
You're looking for a way to store dynamic data. Your best bet would be to use something like Sessions or LocalStorage
Related
Hello I am using laravel 5 to display a 20 column csv from my database, I have a foreach loop displaying 5 of the 20 columns in a table and then a view more button to take you to another page with a table showing all the information of that particular row depending on the id.
My question is how do I pass the id to the other page so I can do another foreach loop to display the rest of the info? I have it so when you hover over the link it's display the id. I know this is vague so if you could point me in the right direction it would be much appreciated as I'm not home at the minute so I can't post my code, thanks!
What you are looking for is called pagination and lucky for you Laravel has made a beautiful function to make this easier documented at https://laravel.com/docs/5.4/pagination.
I need to build a catalog with posts that I get with a query, each page of the catalog will have 27 spots for posts (except for the last page). The problem is that some posts need two spots if there was an image attached when the post was created. I don't have a field in the database that tells me if the post have an image or not, I would add it if is necessary. So far I have this two possible solutions:
1) Get the 27 results and then loop trough them to see how many posts have images and then calculate an offset of the posts that where not displayed so the other page would start with the correct number.
2) Add a field in the database for tracking if a post has an image attached and then run a query with a conditional so I get only the posts I need to get the 27 spots filled.
The problem that I'm having is on how to keep track of these offsets. What happens if the user wants to go to the last page? Do I need to query all the posts and then calculate the offset for that last page?
I'm hoping I'm making some sense, sorry for my english too, I'm not a native english speaker.
Thanks in advance.
You can join both the tables if results are correct and convinent as expected by you and secondly in codeigniter you don't have to worry about the pagination stuff for last and first, the pagination library takes cares for that. For more details on pagination library, visit the below link:
http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
I'am using the CodeIgniter. I have a global category list, which is separated into the several components such as (Conten articles, E-commerce, Users, Banners, etc...). There is /categories/get_categories page where I display all rows from Database Table ci_categories.
On that page, there is a <select> box with the <options> of available ci_categories.com_id (components). Whenever I select one of them, either Users or E-commerce it will send the POST data /categories/get_categories/$com_id and it will filter the category items corresponding to the component's id com_id. All of this works great.
But what I want is to keep this filter selected and do not return to default selection (all components). For example, I click on Categories - it will output all category rows in a <table>. There I choose an option from a dropdown selectbox list, and it will filter the specific rows output, then i Click Add new category, and it should pass that selected component option to the next page. On the next FORM page, where I add a new item informations, i Click on SAVE, and it should return me to the previous page where All of categories are listed, but with that filter com_id selected.
Any suggestion ? Is there a way to do it without sessions or cookies ?
My suggestion is to make use of sessions as they are especially meant to store data between requests based on the current user experience. Most people only search the website in one browser window, so it shouldn't give a real problem. Even if there are other options, you always need to identify the user by a specific code which will be stored in session/cookie.
The only option I can think of is changing every link afterwards to contain the stored information in a base64 encoded string. But that would ruin your link structure and needs canonical links on every page to show the right url to search engines.
I would suggest you to stick to Sessions, as they are handled fine in CodeIgniter. You can even store them in the database if you want by setting that in the main config file.
Flashdata is an option, but it's a session in the end anyway but only lives one request.
you can use session flashdata like this:
Set flashdata
$this->session->set_flashdata('search','your_search');
Read flashdata
$this->session->flashdata('search');
flashdata is setted for only one refresh, after the refresh the variable is deleted
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html
The scenario (all happening within the administration area/backend):
From the listing page, the user clicks a link to view an article (on the backend).
From the article view page, the user clicks a link to edit that article.
In the article edit page, form is submitted to the current uri.
If validation succeeds or user cancels, user is redirected to the article view page.
From the article view page, the user click a 'back' link to return to the listing page.
List <--> View <--> Edit
Right now, I'm only able to track referring url from a previous page. In the edit form, I'm using a hidden field to maintain referral to the view page, lest it be changed during failed form POST submission to itself and user remains in the edit page.
Problem is that when the user returns to the view page from edit, the 'back' link to the listing page is now linked to the edit page.
FYI,
The listing page url is dynamic as the user should return to the listing on the same page and sort order (stored in query strings); therefore a fixed url is out of the question.
In the past, I've tried using sessions (e.g. SESSION['view_to_list_ref'] SESSION['edit_to_view_ref']), but it messed up with multiple tabs.
I could transition between view/edit via ajax, but I'm hoping to keep the app simple and ajaxless at this point of time.
I'm using PHP + Kohana 3.2 Framework
The only solution I can think of is to have the list page url encoded and appended to the 'view article' link via query string. This way, the location of the listing page is preserved even while in the edit page; as the referring url back to view page would also contain the listing page url in the query string. However I don't really like the idea of 'dirtying' the url with long parameter values (encoded or not).
I'm really hoping there is a more elegant solution to this problem of generally tracking multiple levels of page referrals; not just specifically to solving the scenario I've mentioned.
EDIT: Oh and the solution should be able to support multiple tabs performing the same scenario.
You could track the pages by using a unique identifying code in a PHP session, a temporary variable, and using a temporary database table that tracks page loads by these temporary values.
The database structure might be:
+-------------+-------------------+---------------------+
| Unique ID | Page Referral | Time of page load |
+-------------+-------------------+---------------------+
Tracking time of page load would allow you to selectively wipe loads older than X minutes, and keep the table relatively small.
Anyway, this would allow you to keep as many levels as you'd like, and if you wanted to add an auto incrementing counter field, or your own counter field, you could even keep a simple to use number system that tracks page loads, though I believe the time of page load would suffice for that scenario.
I use a SQL database and a WHILE LOOP to display the contents of the database on the main page and am currently trying to incorporate a Facebook "like" button for each and every item on the page.
Currently every item listed in the database is displayed on Shopping.php
I need the server to be able to create a page with a unique address for each item in the database so that the "like" buttons don't all link back to the Shopping.php page.
What I am imagining is something like "/Shopping.php?item=0001" that will link to a page dedicated to that one single item.
Thanks for your time.
Please if you could give a code how to do it , it would be great help
if(isset($_GET["item"]))
{
// Fetch information about item with ID = $_GET["item"] from database and render a page for it.
}
Was that what you were looking for?
Yes this would work, only change is, you need to get the item number from the URL and refine your SQL query.
if(isset($_GET["item"]){
sql = "select * from items where item_id = $_GET['item']";
\\display results after executing this sql
}
But if you want to optimize it to search engine, i recommend you keep your urls as
shopping/item1
shopping/item2 etc