Creating x amount of pages equal to x ID's in database? - php

The title may be a little vague, but I'll try to explain the concept here.
I have a site in which daily new items ( sports games ), get published, now what I would love is that my users would be able to click on a certain game and get redirected to a new page with more detailed information about that one game.
The thing is, creating every php page seperate for every game each day is a lot of work because also a lot details in the page need to be changed.
Now I was wondering if it is possible in some kind of way that there's a script that reads, OK you have 5 games today, page 1 = id number, title of the page is the matches name, extra info is the info that stands with that id.
I don't know how else to explain this so I hope this was good enough.
Thanks for your time and reading this :)

You can use requests to select the page (the best way is to use $_GET as suggested by gbestard) to select the ID. Then you can have some static content (like url or short article or link to screen shot or something similar) stored in your database under the same ID as the game, and upon clicking on the link to the game, the page is reloaded and you populate it with the new content, that was stored in the database.
You can even store entire pages with static html (as in article or short game description in your case) content and etc in your database and simply call them to populate a div.
If you have something like a custom made admin section of your site, you can add a page to edits it with a js plugin like ckeditor and the creation/editing of articles will be a piece of cake.
It's pretty much a standard case of a CMS(Content management system).

Related

Dynamic links in php

I'm almost embarrassed asking this question since I know it should be quite simple yet I can't find an answer to it.
I have a html page with php code in it, that displays let's say a list of companies in a table. I want to make the names of the companies in the table be hyperlinks, such that when a user clicks on a company name, he/she is taken to a page that shows that company's details.
The issue is I cannot have a static page for each company because this list of companies can change every day. So the 'company details' page should be generated dynamically based on what the user clicks.
I am not sure how to approach this. all the questions I see out there seem to talk about static links and pages for static data.
Any guidance is be appreciated!
Every company in the table should have an ID property.
Then when you create the link, do something like this:
Company Name
In your company_details.php you can get the ID of the company from $_GET['id'].
That way you only have one page company_details.php for all companies.

Creating unique pages of a website by passing an sql key

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'].

How can I make only the content refresh, or change, when new parameters i added?

I have a couple of pages where the user can add and remove stuff in order to update the results. i.e. in a "ShoppingList"-page where the user can add/remove drinks in order to see what ingredients they need.
Each of these drinks is stored in a cookie, with PHP, so the user have the ability to navigate and explore the site, and then return without having to add the drinks again...
When the user do this, adds/removes drinks, the entire page is reloaded.
Drinks are added to a cookie immediately, before any html and stuff, then refreshed once again in order to build the php.mysql.query based on the values now stored in the cookie.
I think this is a lot of unnecesary reloading and stuff. It should be something more like just refreshing the actual content that needs to change, and not reloading everything else - Lots of unnecesary mysql requests just to add/remove a drink from the shoppinglist. And this of course slows site down..
Whenever the page is loaded, I need to check the cookie in order to present the correct results. Then, when a user adds/removes a drink, I would like to do this in the background (update the cookie and update the result). Hopefylly this could speed up the user experience.
I have a site up'n'running here - as a "prototype" : http://barkeeper.thomaskile.me/?side=handleliste (norwegian site, but google translate sort of gives you an idea of what it says. just tested it..)
This same thing goes for all three pages on my site so far..
Any suggestion on how to accomplish this? Is it som sort of jquery.AJAX-thing? If so. WHere do I start any sort of ajax-thing. Not sure how that works in practice when the user doesn't do anything (on page load)...
This is usually done by manipulating DOM.
Remove the element from one list and create it in another list.
Checkout jQuery - the javascript library.

How to auto categorise user generated content

I have a system where the user makes a post, this post will include a title, and the post content itself, the content will be anywhere between 20 - 3000 words and consist of plain text.
I also have a set of more then 700 categories, some are top level categories, the rest are subcategories.
When the user enters the content for their post, they need to be prompted with up to 5 relevant categories, selected automatically based on what the user has typed in.
What is the best way to do this, I am using PHP & MySQL, links to any libraries or code samples would be useful.
User perspective
You cannot do this on 1 step in the same page with only php/mysql. There are mainly 2 options for your question.
You also learn/use some client-side language and implement it to do a search without changing the page. I don't know much of it, so I cannot really recommend anything specific, but this thread should help you.
You use a middle page. That said, the user posts it's content, then after sending it you parse it and offer categories for the user to select in the new page. This has the problem that many users might close the window after pressing 'send' in a comment as they expect it to be sent straight, the good thing is that it only uses php/mysql.
Parsing the text
Once again I'm not sure if this is the most efficient way, but I'd try this and keep testing until achieving the result expected:
First, create a list of few keywords for each category. 4 or 5 should do the trick, but it depends greatly on the categories, text and many other factors.
Then, create an array of 10 elements. 5 would be the id of the category and 5 would be the 'score' for each category. You can set, for example, a score of 1 for each keyword found. Remember to asign some values initially or you'll have nothing to compare it to.
Then I'd search each category keywords in the text. If you get an score superior than any of those obtained previously, substitute the minimum one for the new category.
Echo the 5 categories remaining at the end of the script. They should be the 5 more suitable. But keep in mind that there are many more ways to approach this parsing problem.

Update DB column every time a link is clicked via PHP

I have searched online for this issue, but the results are mostly based around Excel.
I have a webpage that has a list of videos. Every time someone clicks on a link, they are taken to a separate page where they can view a video. I have a table in my mysql database that links video id to views. I would like to increment the views column every time someone clicks on the link.
I know how to do this on the database side, but I am trying to figure out how to trigger the DB operation via PHP. I thought about having a script at the top of the page that calls the stored procedure to update the tally everytime the page is loaded, but the problem with this is that the video doesn't start automatic ally when the page loads. Users have to manually click on "play".
Why not write an Update query on the table which gets called everytime a link is clicked?
It is a little confusing where you want to increment the counter. You give three situations:
When a user clicks a link to a particular video's page
When a user loads a particular video's page
When a user clicks play on a video
1 & 2 wouldn't give an accurate count of those who actually watched the video, so I'll choose that you meant 3.
It depends on your video player then. If the player has a way to hook a javascript function to the start of a video, then you can use that to make an ajax request back to a server page that updates your database. If the player has no hooks then you're limited to on page load, which will be less reliable.
Does this help? If I miss understood the question, please clarify by updating the question or adding comments. PS. adding code of what you've tried goes a long away as well.

Categories