I have a database with a list of Games on and i have used a hyper link on all game, my probem is at the moment each entry goes to a different page, I want to the links to go to the same page (i.e display.php) and it get the details from the database and show them on screen.
Hi I am struggle a lot with reading text and learning from text so would be glad if someone could help me with this problem i have with php. I have a list of games printed on screen with the link line as above, i can not get the game name printed on the display page. if anybody could help me or point me in the direction of a tutorial on this subject I would be greatful.
<?php while ($row = mysqli_fetch_assoc($result)):
var_dump($row);
?>```
if this correct i get 'array(4) { ["id"]=> string(1) "1" and so on with all entries in database
By the “display page”, do you mean this page which lists all the games, or the page that you link to which then displays an individual one? If it’s the latter, then obviously that’s the code we need to see to be able to offer advice.
As soon as your first page was displayed, that was the end of the execution of the PHP code that drew it. All the variables are gone.
When you open the new page as a result of the user clicking on your <a> tag, it starts a new execution of, in this case, display.php. Within that, you need to run a new query to retrieve the individual game results, based on the game id parameter that you passed in as part of the URL.
Well, your first code already shows that you know how to connect to the database, execute a query and display the results. You already have the building blocks.
Break the task into separate stages:
Retrieve the game id from the URL and display it on the page.
Write a query (in phpMyAdmin or whatever you use to access the database directly) to retrieve just that game.
Put the query into your display.php code and get it to work with the id that you got in step 1.
Finally, change the query to use prepared statements for security and make sure it still works.