Search code examples
phpmovie

Create custom pages in php


I am currently developing a movie directory in php, the site is connected to my database and the data is displayed in a table, the elements of the section "title" have a link (clickable), and I want it to refer these links to a page movie.php/Aname = "idOfTheMovie" (link Personalized) which displays the info of the database like the poster, the director...

Php code of index.php:

  <?php
$con=mysqli_connect("localhost","root","root","movie");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM allmovie");

echo "
<center>
<table border='1'>
<tr>
<th>Title</th>
<th>Director</th>
<th>My score</th>
<th>imdb note</th>
<th>Time</th>
<th>Year</th>
<th>Type</th>
<th>Poster link</th>
</tr>
</center>";

while($row = mysqli_fetch_array($result))
{

echo "<tr>";
echo "<td><a target='_self' href='movie.php?Aname=" . $row['id'] ."'>". $row['title'] . "</a>";"" . $row['title'] . "</td>";
echo "<td>" . $row['director'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['imdb_score'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['poster_link'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

I try many codes for the movie.php page but I don't find the good Thanks :)


Solution

  • You can use the php $_GET[] global variable to get your goal.

    example: movie.php

    <?php 
    $id = $_GET['Aname'];
    
    if (empty($id)) { 
        echo "an error occured"; 
    } else {
        $code = 'SELECT * FROM allmovie where id = "$id"'; 
        $data = mysqli_query($code);
        while ($row = mysqli_fetch_array($data)) {
            //some codes
        }
    }
    ?>
    

    hope it helps. correct me if i made a mistake.