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.
**
Related
The title may be a bit awful as I'm really not sure how to describe what I'm trying to achieve without using lots of words.
I'm currently building an events website. This website has the option for users to create their own events which can be added to a big list of upcoming events that other users have submitted.
What I want to do is be able to have a user create an event and have the details of the event stored in an SQL database (which I've successfully done), I want to be able to then have a large list of events on a separate page the details of which are pulled from the server dynamically using PHP and SQL (I've also successfully done this). The part I am struggling with however is being able to create unique pages (or a single dynamic page) that displays a more detailed look at the event, such as age restrictions etc etc, which cannot be displayed on the big list which displays all the available events.
I figured that this could be done using a unique eventID, which is something the SQL database already includes and autoincrements with each new event entry. What I'm really not sure about is how I'd be able to pass that eventID through the link to the more detailed page so that the detailed page can be created displaying all of the details of the event.
I'm not even sure if this idea will work at all. Would having a page with a unique URL that is created on event submission that has a more in-depth look at the details of the event be a better idea? How would I go about creating unique URL webpages that correspond to each event on event submission?
I'm really not sure how I need to go about this at all, so I need some help and pointing in the right direction.
Here's a kind of TLDR:
1) Events website
2) All events on the website are displayed on a single page that has minimal detail about each event (title, date, location) BUT has a link to a page that displays the event in more detail.
3) User can select an event from the list and click on that event's unique HTML link to more detailed page
4) More detailed page displays event in more detail by pulling event's unique information from the database
Feel free to ask any questions at all as I know this probably isn't the easiest idea to get across
When creating the links from the general listing page to the detail page, simply include the id in the link. For example:
<A HREF="mysite.com/detail.php?id=3>Big Event</A>
In detail.php then, you'll find the id in $_GET['id'].
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'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'm building a CRUD application and need to implement two forms of search:
The basic search function accepts a keyword and searches every column in the database table for that particular keyword. The search keyword is sent as an URL-parameter in the form www.website.com/category?q=keyword. Nothing too special here...
In the advanced search form users can specify up to 5 keywords and for each of those they can select a column from the database table which needs to be searched for this keyword. In short: the advanced search form takes up to 5 keyword-column pairs. This form gets submitted via POST (because i want to avoid hitting limitations on maximum number of URL-characters).
The results need to be paginated, showing 10 records per page. I've searched for pagination classes online, but they all fetch the total amount of records in the database table, and then return the selection that needs to be displayed for that page. Because I'm working with a large set of data here, I can't afford to do it this way.
This lead me to create my own pagination class, which takes the requested page number (and if applied, the $_GET and $_POST parameters from the search forms). Based on that it calculates the total number of results, calculates the total number of pages, decides whether there's a 'previous' and 'next' page... It also returns an SQL statement (with LIMIT and OFFSET values) to be executed by the particular Model (using my own MVC architecture (aka no framework)). This allowed me to only fetch the results for the requested page.
Problem: when the user navigates through the pages (aka clicking 'previous' or 'next' buttons), the $_POST data is lost. However, these values are needed in order to get the results for another page.
This particular problem made me think about the search forms on forums. I submitted a query on one of them and noticed a search ID getting appended to the URL:
example.com/forum/search.php?searchid=5672532
This means that the form data is being kept somewhere, somehow... and I'm thinking what the best option might be, from most to least plausible:
- Database table where each search input gets saved for e.g. 30 minutes
- Sessions
- Files
(hidden fields are obviously not an option, because they need a form submit button to be pressed in order to get sent with the request)
I'd like to here your opinions on this, some of you must have encountered this problem already...
Saving the search parameters in JSON or URL encoded in a database for a set amount of time (have an expiry column) seems the best solution.
Note that in that way, you'll need to query the database over and over, with different LIMIT clauses.