Giving Information with PHP,MySQL without Reloading - php

I want to give some information from my database without creating 100 different .php files and redirecting users to each file according to what they want. Is there a possible way i could do that with one page?
I have a table on database named players(basketball players). I want page to be reloaded and print table players(i know how to print) without redirecting to another page which i should make. How i could do that?
For example: Player goes to my leagues.php page(webpage with information about basketball teams) then players clicks on Barcelona team and then it reload page with players of Barcelona(loaded from MySQL database). Is there any possible way? I couldn't find any similar question like that.(If there is i apologise i don't speak proper English and probably i couldn't understand it well!).

Related

PHP pages dynamically?

I'm not asking any coding question, I'd just like to know what the 'standard' practice is. If I had PHP spit out a table or list of names/items from a database and then when you click on one of the names/items it then takes you to that page, should these pages be made dynamically or not?
For example, if it was a list of musicians, and then when you click on a musicians name it takes you to a list of their albums and then when you click on the album it has the track list, should these links/pages be done dynamically or is it best to make each musicians page normally. Basically, what I'm asking is should PHP be used to make each page or just to echo out the tables from the database.
Thank you.

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

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).

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.

Keeping track of more than one level of page referrers

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.

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