I am trying to build a project in which links to different pages(php) are given on a page. I have a variable which gets the unique id from the link and accordingly displays content based on the id. The user is allowed to delete/edit the content.
When a user clicks two(or more) links one after the other, the second's link id is stored in the variable and if the user presses the delete button on the first link's page the second one gets deleted as the variable has the id from the second(last pressed) link.
I don't want the variable to get modified and each link should be treated as a separate entity. Please tell me how to solve this problem.
A unique id is sent to the class through the link and based on the id content is displayed to the user.There is an option to edit/delete the content and if two links are clicked the id is getting overwritten and the wrong content is deleted. In order to avoid that i want an object created every time so that each object will have its own variables and id is not overwritten
You could pass something in from the query string or some other request context variable.
Related
I have two pages, one is a new player page which takes information from a user via text box and adds a new entry to the players db and creates a new auto-incremented primary key called playerID. This is working fine.
I then have another page called stat input where the user will enter statistics for an individual year for an existing player. I need a way for this second page to know the playerID of the player whose information is being added. I am not unsure of a good way to do this. Any ideas are appreciated.
Edit: I guess I wasn't very clear. The user may be going directly to the stat input page to add a new entry to an already existing player. The user will not know the playerID and likely only the name of the player.
There are a few ways you could do this. Once you have the player ID, you can store it in a PHP session variable (if you are open to using server-side sessions). You could also pass it in a GET or POST parameter to the second page.
Edit:
As per the additional information you gave, I would go with a dropdown box with each player name. In the box, the "value" attribute of each can be the primary key ID of the player.
I have one page where the user will enter information about a school assignment (what school it belongs to, what class it belongs to, and the assignment's name).
Next, I have a second page where the user will enter the actual content of the assignment.
I need both sets of data to be passed to one class called AddAssignment. How do I go about storing the data from the first page along with the data from the second page?
I think in both pages you are using Form to submit and save information.
you can pass data of both pages to one class called AddAssignment.
First page form submit button having name AddAssignmentName and second page's submit button name AddAssignmentContent and these parameter differentiate date when you submitting details from any one of the page then you may perform your other information.
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
I need store different post data to each tab in a browser. If I open a new instance of the same page, the data aren't shared between both.
My problem:
I'm building a CMS to control my website content. But I will open some instances of the same page (many tabs). So I have a search form to find news that I been created on my CMS. If I open a news item I have a cancel button that back to previous page (the news list).
The problem is that the news list have a pagination and a filter form. So I can, for instance, search by a term like "john doe" and advance to page 5, and open a news item. If I cancel, currently I back to news list without filter and on first page.
My solutions:
Well, I don't want to use the history.back() because I can submit a news form and click on back/cancel button. So, I'll back to the current form, what is wrong.
My second idea is to store a $_SESSION with the $_POST sent to the news list and the back button send me to /news/list/recovery-session, that will recovery the $_POST data from session. But it have a problem: if I open two tabs and make two searchs, I'll have only the last session saved.
Your solutions:
Well, I can work with PHP and JS to make it work. You can suggest a idea of what I can do. I think about work with COOKIES, but I belive that it is shared by domain, and not by tab, what is a problem.
Someone?
Generate a unique id and attach it to the form or some hidden element that will be submitted. Save that unique id in a cookie or session variable. Compare the two at time of submission.
If second tab has generated a new id, the first tab will not evaluate to true.
The main problem is the need to persist the state of what page to return to and also the search term when returning back to the news list page. There are many ways to accomplish this, but one simple method is by encoding this data into your query string.
As an example, assuming your search term is "john doe" and you are on page 5, pass that data along to your news page.
news.php?returnSearchTerm=john+doe&returnPage=5& ....
When the news page is created, you can format your cancel link to send you back to the list page with the correct parameters.
news_list.php?search=john+doe&page=5
Some background: I'm working on a member directory page which displays member information gathered from a MySqL database. I have a loop set to display name, id#, title, etc from each member - one member per row. The displayed member list can be searched and sorted so will be anywhere from 0-20 entries long (20 max per page).
Each member's name can be clicked and more information pertaining to them is displayed. For example, if the user clicks on "John Doe"'s name, an "individual info" page for John is included, splitting the list of names (the info is included directly after his name's listing, but before the next member's listing - ["John Doe, #333" / "Jane, #777"] turns into "John Doe, #333 / {John is a graduate from...}" / "Jane, #777"]).
I currently populate my page with PHP so the list is inside of a form and their names are displayed as inputs so when the user clicks them, the form action ($self) is run. I have the form value set to the member's name so that users can see readable names. I have the input's name set to the member's id# and run a if(isset($_POST['userID']) inside my loop to determine which member's individual information is displayed. So, the loop runs through the MySQL query, displaying name,id... for each member and if curID# == $_POST['userID'], it also displays the corresponding individual information.
My Issue: The problem I'm encountering is that my list is rather long on the page, especially with individual information displayed so I want to be able to jump to the member's info on the page using anchors corresponding to their ID#. I have the anchors set up, I can manually navigate to memList.php#ID333, but I want to navigate there when the user clicks on the name.
I can set up my form action to navigate to $self#$curID, but $curID is the variable name for the member's name input, not the value of it.
What Hasn't Worked: I've attempted hidden fields with their ID as the value and curiD as the name, but they do not work because my loop resets it for every member (hence, $_POsT['curid'] is always set to the bottom-most member, not the one the user clicked).
I've had the names as href links, but then my search and sort $POST values are not resent (the page is basically refreshed from the start).
My Question, Shorthand: Is there any way I can setup an input field to display a member's name, yet have their ID sent as the value?
If I understood correctly, this sounds like something that would be best done using a javascript autocompleter. If you're using jQuery, here is a link to their autocomplete plugin. Check out the demo and see if this kind of approach suits your needs.