Dynamic links in php - 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.

Related

How to click on a button and its refresh the page with the new data in PHP?

I have been coding in PHP for not very long and I have a site where we have people and their people are on a given database (MYsql). Each name is linked to other names using ids. Each person has their page and I would like that if I am on the page of a person and the name of another is displayed, clicking on it refreshes the page with the data of the second person.
expl:
Jean's page (with his surname, first name, Age, (Michel) father, (Mireille) Mother) and when I click on father, the same page is displayed to me but with Michel as the name.
thank you very much for your answer
I tried to have the father's name displayed in a text input in a form and retrieved it with "if(isset($get['lenomduformulaire']) and I tried with post too. But that didn't m displayed that the variable did not exist.
I also tried to put it in a button tag and same as before it didn't work.
What you're describing just sounds like a link. For example:
Mother
Basically the data for the current page would (should) include identifiers for the linked objects. For example, if the current person's "mother" has an ID of 123. You'd populate the link with that person's mother's ID:
Mother
(Or however you structure your data and identify your records, this is just for illustration purposes.)
When clicking on that link, the user is directed to "the same page" but with the ID value of another person. person.php always just uses whatever ID is provided to query the data and display the "person".
before answering your question I highly encourage you to use a PHP framework, like codeigniter or Laravel, this is very convenient for PHP starters.
Now answering your question and taking the previous answer, given by #David I would say that you can do it like this:
Mother

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

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

php report button

I am working on a search script and on each search result I want a report link button. I am not sure how to make one. I have looked on google for answers but cannot come up with anything. Can anyone give me an idea of what to do? or does anyone know where there is an example of this? I plan on using the link id and making a new table on mysql to send reports to. I am just looking for a basic button to send reports to mysql I am just not sure what would be the best way to do it. I have the data for the link id's I just need to be able to report it to a new table I am assuming. Any suggestions or examples are very appreciated. Thanks.
Chris,
First you will want to create that new table in your database to capture this information. Lets assume to you will have the following fields (very basic, you may want to add more): ReportId, LinkId, DateReported. ReportId is our primary key, LinkId is the ID you reference in your question and the DateReported is the server time we logged the transaction.
With this table created you are going to want to create a new php page, lets call it report-link.php. You are going to want to make this page accept a querystring variable called linkid (accessible in the $_GET[] collection). In the code of this page you will want to write a SQL query that inserts the value of the linkid parameter into the new link report table in the database (along with the date()).
On your search page you will be able to have users report an entry by clicking a link with the href of /path/to/report-link.php?linkid=<?php echo $link_id; ?>
Please note this example is very simplistic in nature, and offers no security for spamming, pleasant end user experience after they click the link, but this is the process you will want to follow in setting this feature up. After you have it working you can spruce up the experience for your users.

Categories