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.
Related
I'm currently developing a database/website server interface to facilitate inputting data for a data collection project. There are two types of additions being made to the database: A and B here. Some of the tables in the database that handle these entries are as follows:
dcs_projectname_a
dcs_projectname_b
Each of these have tables for all the required input fields in addition to things like creator, timestamp, etc.
The pages on the website facilitate three different options: add, view, and edit. Each page for each type of entry performs the respective function. That is, the add page adds, view page views, etc.
I am just about done; however, there is a major challenge I haven't really confronted yet: concurrency. There will be multiple users adding content to the database at the same time. Each entry is given its own specific id and there CANNOT be any duplicate id's. That is, the first a entry is A000001, the next is A000002, and so on.
On the add and edit pages, there is a disabled field for the user to view the id for other uses when physically documenting entries.
What I need to figure out is how to implement concurrency management so that when users are concurrently adding a's that they will not be under the same id and row.
The add page automatically generates the id to be used by accessing the database's most recent id and adding one.
My thought was to create a new row in the table every time the add page is opened and give it the calculated id. Then, when information is added it performs a modification to that existing row. This way, if another user opens the add page while another entry is currently being added it will be given the future id, not the same one.
With this method I need a way to delete this entry if the user leaves the add page or closes the browser. Then, I also need other users with open add pages to automatically update their id's to one less when the first user (or any other user less than the most id being used) leaves their add page and cancels the addition.
This is kind of a complicated explanation and if you don't understand let me know and I'll try to answer as best as I can. Any help is much appreciated!
Thanks
There's a number of solutions to your problem, but you seem to have made things harder by having your application generate the record IDs for you.
Instead, you could just be using MySQL's AUTO_INCREMENT functionality to automatically generate/increment the record ID for you (upon insert). MySQL will ensure that there are no duplicates, and you can get rid of the extra database call to retrieve the most recent ID.
I am trying to generate a unique slug for pages based on the title of the post the user enters so, say a title is "Once upon a time" this will translate into Slug->once-upon-a-time, however I want people to be able to have matching titles so if another person comes along with the same title I then want the slug to be Slug->once-upon-a-time2. How can this be done in laravel or just php. I essentially just want to try and save but if it fails then increment and then save again. Thanks for any info
This isn't exactly an answer but why not separate by user and allow them to have identical post names? For example 'www.example.com/users/{user_id}/posts/once-upon-a-time', would avoid this issue completely and allow for checking out individual users writing.
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.
This is a pretty long and hefty question. First off I am new to PHP but I know javascript and HTML as well as CSS. I have created the static elements of a webpage and have managed to integrate it with a login and signup premade php layout, so currently users can signup and login for the site. However the key element remains; the user should be able to select an item from the database and upon selection that item should be "pinned" to a specific div.
e.g. The user clicks on a button below "image.div", when the user clicks on this button a modal pops up with some choices, the user have to select a choice which then loads further information for the user to see. Upon getting this information the user clicks "pin" and the modal closes and that specific choice is "pinned" to "image.div". Each individual "image.div" will have it's own category, e.g. hotels, car rentals, restaurants etc. Ence when selected only the assigned category is displayed by "image.div".
The "pinned" object should only be view able by the user that pinned it when that user logs in.
I also want the choice within the popup modal to be searchable by keywords e.g. kingston, New York etc.
The database that came with the php login scripts have the following table: fgusers
The table has the following columns: id_user, name, email, phone_number, username and password.
In addition to the above information request I would also like to know how to structure the database for this, should I extend the fgusers table? or should I create separate tables for each?
A response would be greatly appreciated.
If I understand your question correctly then, the best way to achieve the effect you are after is to use AJAX to access database info via a PHP script. Then use javascript to manipulate the xmlhttp result.
As far as the MySQL database tables go, it is better to create separate tables for the different information. You will need to create a column in each table that references an identifying column in the table you want to link that particular tables information to.
Then you just have to use the JOIN commands when referencing the table data.
Example: if you want to link data to specific users you can add a username column to the table and add the users name to the data row. Later when you want to retrieve that users data, just reference the users name. If there are multiple tables of user data, use the JOIN command to link the tables together.
In case this question has been asked before just refer me to the answer and I shall be greatful.. it's a very common problem however I have not been able to find solution form google
I am developing a website in PHP using codeigniter. I have articles /Posts. These posts are located in a database and when ever a user demands to see an Article, all its relevant data is pulled from database using a unique "Content_id" and a page is presented to user dynamically.
However once the data is dispatched to the view and an html page is created from that page I have no way of finding which "Content_id" was used in generating that page. Now in case user comments on that page I dont know which "content_id" to save in the comments table along with this comment so that next time when this article is displayed then all the relevant comments can also be displayed.
some of the solutions that I thought are as follows
Can I use session to store this data? (However I am not using sessions for those users who are not logged in ... So can I use sessions for all users )
Will using a form on the page with hidden fields be a viable option...
How do Wordpress or other CMS are handle this problem?
To achieve your goal, your table needs four columns:
Unique row number
Content
Post number
Post date (timestamp)
The unique row number is the primary key. Auto_increment it.
The content is the posted message.
The post number is the row number of the post that starts the conversation. Make it the same as the row number in the conversation's first post. It is the row number of the post being responded to. All responses to the conversation will have the same post number.
The post date is a timestamp. It permits you to organize the order of the posts in a particularized conversation.
Each conversation, or sub_conversation, follows this routine.
Usually, the post id is passed as a GET variable anyway. If not, a hidden input is fine.
I am Very sory to Know that no one answerd my question except one persone
Any ways here is the solution that I have figured out in 1 sentence **
The pages are not required to be numbered But the content needs to be numbered... thus each content (Article, post etc) has a content id and that id needs to be considered.
**