PHP - Generating a link with a picture

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
Tendoken
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Apr 26, 2019 2:52 pm

Fri Apr 26, 2019 3:01 pm

Hi,
I am a complete beginner in PHP.
I am trying to create an online movie site as a training.
However, I am stuck on the last part.
I have created a first page with a list to sort the movies by year.
A second displaying the movies that were released the year selected.
And a third page when clicking on the picture in page 2 as a recap the picture of the movies, its title, synopsis and the year of released using the _GET method and generating a html link.
I have problems as I select the year on the first page, on the second my code is generating the details of all the movies for all the years, and to make things worse, when clicking on the picture, the first set is matching the first year, the second, the second year and so on. I spent days trying to fix this issue but I cannot manage.
Could anyone help please?
See below my (shorten) script.
Many thanks in advance.

****************Page 1*****************************
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Cinéfil online</title>
</head>
<body>
<form action="movies.php" action="page1.php" method="get">
<fieldset>
<legend>Films</legend>
<p>
<label for="picture">Recherche de films par année :</label>
<select name="picture" id="picture">
<option value="2014">2014</option>
<option value="2015">2015</option>

</p>
<p id="submit" class="search">
<input id="bt" type="submit" name="Rechercher" value="Rechercher">
</p>
</fieldset>
</form>

</body>
</html>
************************Page 3 ******************************

<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">

<?php

$image = $_GET[ "image"];

$movie = $_GET[ "movie"];

$synopsis = $_GET["synopsis"];

?>

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css">
<title>Cinéfil Online Page 3</title>
</head>
<body>
<div id="wrapper">


<header id="main-header">

<nav id="main-nav" class="main-nav">
<ul>
<li class="nav-link"><a href="#">HOME</a></li>
<li class="nav-link"><a href="#">MOVIES</a></li>
<li class="nav-link"><a href="#">TV SHOWS</a></li>
<li class="nav-link"><a href="#">GENRE</a></li>
<li class="nav-link"><a href="#">YEARS</a></li>
</ul>
<label for="search">Search:</label>
<input type="search" id="search" name="search"
aria-label="Search through site content">
<button>Search</button>
<div class="clear"></div>
</nav>
</header>
<main id="main">
<section class="infos">
<h1><?php echo $movie; ?></h1>

<ul class=" details">
<li> Genres: Action, Drama, Thriller </li>
<li>Release date: 2016 </li>
<li>Language: English, French </li>
</ul>

</section>
<section id="left" class="fl">
<?php echo '<img src="' .$image. '" height="345" width="235" />' ; ?>
</section>
<section id="right" class="fl">

<video src="videoplayback.mp4" controls poster="sintel.jpg" width="610" height="350">
</video>
</section>

<div class="clear"></div>
<section class="infos">
<h3><?php echo $movie; ?></h3> <p><?php echo $synopsis; ?></p>
<img id="formats" src="formats.png" alt="formats" width="865">

</section>


</main>



</div>
</body>
</html>



****************Page 2*****************************
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<!--<link rel="stylesheet" href="styles.css"> <!--************Added CSS -->
<?php

$images = [
['picture'=>'2014', 'image1'=>'img/hercules.jpg','movie1'=> 'Hercules','synopsis1' => 'Having endured his legendary twelve labors, Hercules, the Greek demigod, has his life as a sword-for-hire tested when the King of Thrace and his daughter seek his aid in defeating a tyrannical warlord', 'image2'=>'img/anarchy.jpg', 'movie2' => 'The Purge : Anarchy', 'synopsis2' => 'Three groups of people intertwine and are left stranded in the streets on Purge Night, trying to survive the chaos and violence that occurs. ', 'image3'=>'img/lucy.jpg', 'movie3' => 'Lucy', 'synopsis3' => 'A woman, accidentally caught in a dark deal, turns the tables on her captors and transforms into a merciless warrior evolved beyond human logic.', 'image4'=>'img/dracula-untold.jpg', 'movie4' => 'Dracula Untold','synopsis4' => 'As his kingdom is being threatened by the Turks, young prince Vlad Tepes must become a monster feared by his people in order to obtain the power needed to protect his own kingdom.', 'image5'=>'img/the-hobbit.jpg', 'movie5' => 'The Hobbit, Batte of the Five Armies', 'synopsis5' => 'Bilbo and company are forced to engage in a war against an array of combatants and keep the Lonely Mountain from falling into the hands of a rising darkness.', 'image6'=>'img/the-amazing-spider-man-2.jpg', 'movie6'=> 'The Amazing Spider Man 2', 'synopsis6' => 'When New York is put under siege by Oscorp, it is up to Spider-Man to save the city he swore to protect as well as his loved ones.', 'image7'=>'img/edge-of-tomorrow.jpg', 'movie7' => 'Edge of Tomorrow', 'synopsis7' => 'A soldier fighting aliens gets to relive the same day over and over again, the day restarting every time he dies.', 'image8'=>'img/grudge-match.jpg', 'movie8' => 'Grudge Match', 'synopsis8' => 'A pair of aging boxing rivals are coaxed out of retirement to fight one final bout, thirty years after their last match.', 'image9'=>'img/jamesy-boy.jpg', 'movie9' => 'Jamesy Boy', 'synopsis9' => 'A young gang member turns his life around in prison, thanks to the friendship he forms with a convicted murderer who becomes his mentor.', 'image10'=>'img/noah.jpg', 'movie10' => 'Noah', 'synopsis10' => 'Noah is chosen by God to undertake a momentous mission before an apocalyptic flood cleanses the world.'],

['picture'=>'2015', 'image1'=>'img/avengers-age-of-ultron.jpg','movie1'=> 'Avengers Age of Ultron', 'synopsis1' => 'When Tony Stark and Bruce Banner try to jump-start a dormant peacekeeping program called Ultron, things go horribly wrong and it is up to Earth mightiest heroes to stop the villainous Ultron.', 'image2'=>'img/jurassic-world.jpg', 'movie2' => 'Jurassic World', 'synopsis2' => 'A new theme park, built on the original site of Jurassic Park, creates a genetically modified hybrid dinosaur, the Indominus Rex, which escapes containment and goes on a killing spree.', 'image3'=>'img/survivor.jpg', 'movie3' => 'Survivor', 'synopsis3' => 'A Foreign Service Officer in London tries to prevent a terrorist attack set to hit New York City, but is forced to go on the run when she is framed for crimes she did not commit.', 'image4'=>'img/the-wave.jpg', 'movie4' => 'The Wave', 'synopsis4' => 'Although anticipated, no one is really ready when the mountain pass above the scenic, narrow Norwegian fjord Geiranger collapses and creates an 85-meter high violent tsunami.', 'image5'=>'img/spectre.jpg', 'movie5' => 'Spectre', 'synopsis5' => 'A cryptic message from 007 past sends him pitted against a mysterious terrorist organization called Spectre, and learns of its involvement in previous events of his most dangerous missions.', 'image6'=>'img/chappie.jpg','movie6'=> 'Chappie', 'synopsis6' => 'In the near future, crime is patrolled by a mechanized police force. When one police droid, Chappie, is stolen and given new programming, he becomes the first robot with the ability to think and feel for himself.', 'image7'=>'img/terminator-genisys.jpg', 'movie7' => 'Terminator Genisys', 'synopsis7' => 'When John Connor, leader of the human resistance, sends Sgt. Kyle Reese back to 1984 to protect Sarah Connor and safeguard the future, an unexpected turn of events creates a fractured timeline.', 'image8'=>'img/the-last-kingdom.jpg', 'movie8' => 'The Last Kingdom', 'synopsis8' => 'As Alfred the Great defends his kingdom from Norse invaders, Uhtred - born a Saxon but raised by Vikings - seeks to claim his ancestral birthright.', 'image9'=>'img/focus.jpg', 'movie9' => 'Focus', 'synopsis9' => 'In the midst of veteran con man Nickys latest scheme, a woman from his past - now an accomplished femme fatale - shows up and throws his plans for a loop.', 'image10'=>'img/kingsman-the-secret-service', 'movie10' => 'Kingsman The Secret Service', 'synopsis10' => 'A spy organization recruits an unrefined, but promising street kid into the agencys ultra-competitive training program, just as a global threat emerges from a twisted tech genius.'],

];


$picture=$_GET['picture'];

foreach ($images as $key => $image)
{
if ($picture==$image ['picture'])
{
var_dump($picture);

echo '<div id="wrapper" >';

echo "<h2> Résultats de recherche pour les films sortis en " .$image ['picture']. ' :</h2><br/>' ;
echo '<table>';

echo '<tr>';


echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/hercules.jpg&amp;movie=Hercules&amp;synopsis=Having endured his legendary twelve labors, Hercules, the Greek demigod, has his life as a sword-for-hire tested when the King of Thrace and his daughter seek his aid in defeating a tyrannical warlord&amp;"><img src="' .$image ['image1']. '" height="220" width="148" /><p>' .$image ['synopsis1'].'</p><figcaption>'. $image ['movie1'].'</figcaption> </a> </td>';


echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/anarchy.jpg&amp;movie=The Purge : Anarchy&amp;synopsis=Three groups of people intertwine and are left stranded in the streets on Purge Night, trying to survive the chaos and violence that occurs.&amp;"><img src="' .$image ['image2']. '" height="220" width="148" /><p>' .$image ['synopsis2'].'</p><figcaption>'. $image ['movie2'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/lucy.jpg&amp;movie=Lucy&amp;synopsis=A woman, accidentally caught in a dark deal, turns the tables on her captors and transforms into a merciless warrior evolved beyond human logic.&amp;"><img src="' .$image ['image3']. '" height="220" width="148" /><p>' .$image ['synopsis3'].'</p><figcaption>'. $image ['movie3'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/dracula-untold.jpg&amp;movie=Dracula Untold&amp;synopsis=As his kingdom is being threatened by the Turks, young prince Vlad Tepes must become a monster feared by his people in order to obtain the power needed to protect his own kingdom.&amp;"><img src="' .$image ['image4']. '" height="220" width="148" /><p>' .$image ['synopsis4'].'</p><figcaption>'. $image ['movie4'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/the-hobbit.jpg&amp;movie=The Hobbit, Batte of the Five Armies&amp;synopsis=Bilbo and company are forced to engage in a war against an array of combatants and keep the Lonely Mountain from falling into the hands of a rising darkness.&amp;"><img src="' .$image ['image5']. '" height="220" width="148" /><p>' .$image ['synopsis5'].'</p><figcaption>'. $image ['movie5'].'</figcaption> </a> </td>';

echo '</tr>';

echo '<tr>';

echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/the-amazing-spider-man-2.jpg&amp;movie=The Amazing Spider Man 2&amp;synopsis=The Amazing Spider Man 2', 'synopsis=When New York is put under siege by Oscorp, it is up to Spider-Man to save the city he swore to protect as well as his loved ones.&amp;"><img src="' .$image ['image6']. '" height="220" width="148" /><p>' .$image ['synopsis6'].'</p><figcaption>'. $image ['movie6'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/edge-of-tomorrow.jpg&amp;movie=Edge of Tomorrow&amp;synopsis=The Amazing Spider Man 2','synopsis=A soldier fighting aliens gets to relive the same day over and over again, the day restarting every time he dies.&amp;"><img src="' .$image ['image7']. '" height="220" width="148" /><p>' .$image ['synopsis7'].'</p><figcaption>'. $image ['movie7'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/grudge-match.jpg&amp;movie= Grudge Match&amp;synopsis=A pair of aging boxing rivals are coaxed out of retirement to fight one final bout, thirty years after their last match.&amp;"><img src="' .$image ['image8']. '" height="220" width="148" /><p>' .$image ['synopsis8'].'</p><figcaption>'. $image ['movie8'].'</figcaption> </a> </td>';


echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/jamesy-boy.jpg&amp;movie=Jamesy Boy&amp;synopsis=A young gang member turns his life around in prison, thanks to the friendship he forms with a convicted murderer who becomes his mentor.&amp;"><img src="' .$image ['image9']. '" height="220" width="148" /><p>' .$image ['synopsis9'].'</p><figcaption>'. $image ['movie9'].'</figcaption> </a> </td>';
echo '<td id="block"><a href="page1.php?picture=2014&amp;image=img/noah.jpg&amp;movie=Noah&amp;synopsis=Noah is chosen by God to undertake a momentous mission before an apocalyptic flood cleanses the world.&amp;"><img src="' .$image ['image10']. '" height="220" width="148" /><p>' .$image ['synopsis10'].'</p><figcaption>'. $image ['movie10'].'</figcaption> </a> </td>';
echo '</tr>';


echo '</tr>';
echo '</table>';

echo "</div>";

/////////////////////////////////2015//////////////////////////////////////
/////////////////////////////////2015//////////////////////////////////////

var_dump($picture);

echo '<div id="wrapper" >';

echo "<h2> Résultats de recherche pour les films sortis en " .$image ['picture']. ' :</h2><br/>' ;


echo '<table>';

echo '<tr>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/avengers-age-of-ultron.jpg&amp;movie=Avengers Age of Ultron&amp;synopsis=When Tony Stark and Bruce Banner try to jump-start a dormant peacekeeping program called Ultron, things go horribly wrong and it is up to Earth mightiest heroes to stop the villainous Ultron.&amp;"><img src="' .$image ['image1']. '" height="220" width="148" /><p>' .$image ['synopsis1'].'</p><figcaption>'. $image ['movie1'].'</figcaption> </a> </td>';


echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/jurassic-world.jpg&amp;movie=Jurassic World&amp;synopsis=A new theme park, built on the original site of Jurassic Park, creates a genetically modified hybrid dinosaur, the Indominus Rex, which escapes containment and goes on a killing spree.&amp;"><img src="' .$image ['image2']. '" height="220" width="148" /><p>' .$image ['synopsis2'].'</p><figcaption>'. $image ['movie2'].'</figcaption> </a> </td>';


echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/survivor.jpg&amp;movie=Survivor&amp;synopsis=A Foreign Service Officer in London tries to prevent a terrorist attack set to hit New York City, but is forced to go on the run when she is framed for crimes she did not commit.&amp;"><img src="' .$image ['image3']. '" height="220" width="148" /><p>' .$image ['synopsis3'].'</p><figcaption>'. $image ['movie3'].'</figcaption> </a> </td>';


echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/the-wave.jpg&amp;movie=The Wave&amp;synopsis=Although anticipated, no one is really ready when the mountain pass above the scenic, narrow Norwegian fjord Geiranger collapses and creates an 85-meter high violent tsunami.&amp;"><img src="' .$image ['image4']. '" height="220" width="148" /><p>' .$image ['synopsis4'].'</p><figcaption>'. $image ['movie4'].'</figcaption> </a> </td>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/spectre.jpg&amp;movie=Spectre&amp;synopsis=A cryptic message from 007 past sends him pitted against a mysterious terrorist organization called Spectre, and learns of its involvement in previous events of his most dangerous missions.&amp;"><img src="' .$image ['image5']. '" height="220" width="148" /><p>' .$image ['synopsis5'].'</p><figcaption>'. $image ['movie5'].'</figcaption> </a> </td>';

echo '</tr>';

echo '<tr>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/chappie.jpg&amp;movie=Chappie&amp;synopsis=In the near future, crime is patrolled by a mechanized police force. When one police droid, Chappie, is stolen and given new programming, he becomes the first robot with the ability to think and feel for himself.&amp;"><img src="' .$image ['image6']. '" height="220" width="148" /><p>' .$image ['synopsis6'].'</p><figcaption>'. $image ['movie6'].'</figcaption> </a> </td>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/terminator-genisys.jpg&amp;movie=Terminator Genisys&amp;synopsis=When John Connor, leader of the human resistance, sends Sgt. Kyle Reese back to 1984 to protect Sarah Connor and safeguard the future, an unexpected turn of events creates a fractured timeline.&amp;"><img src="' .$image ['image7']. '" height="220" width="148" /><p>' .$image ['synopsis7'].'</p><figcaption>'. $image ['movie7'].'</figcaption> </a> </td>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/the-last-kingdom.jpg&amp;movie=The Last Kingdom&amp;synopsis=As Alfred the Great defends his kingdom from Norse invaders, Uhtred - born a Saxon but raised by Vikings - seeks to claim his ancestral birthright.&amp;"><img src="' .$image ['image8']. '" height="220" width="148" /><p>' .$image ['synopsis8'].'</p><figcaption>'. $image ['movie8'].'</figcaption> </a> </td>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/focus.jpg&amp;movie=Focus&amp;synopsis=In the midst of veteran con man Nickys latest scheme, a woman from his past - now an accomplished femme fatale - shows up and throws his plans for a loop.&amp;"><img src="' .$image ['image9']. '" height="220" width="148" /><p>' .$image ['synopsis9'].'</p><figcaption>'. $image ['movie9'].'</figcaption> </a> </td>';

echo '<td id="block"><a href="page1.php?picture=2015&amp;image=img/kingsman-the-secret-service.jpg&amp;movie=Kingsman The Secret Service&amp;synopsis=A spy organization recruits an unrefined, but promising street kid into the agencys ultra-competitive training program, just as a global threat emerges from a twisted tech genius.&amp;"><img src="' .$image ['image10']. '" height="220" width="148" /><p>' .$image ['synopsis10'].'</p><figcaption>'. $image ['movie10'].'</figcaption> </a> </td>';

echo '</tr>';


echo '</tr>';
echo '</table>';

echo "</div>";

?>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 831
Joined: Mon Feb 22, 2016 5:52 pm

Sat Apr 27, 2019 11:27 am

It doesn't look as though you have a form in page 2?

Post Reply