0

I have been trying to create a unique page for each row in my database. My plan is to create a dictionary.php?word=title url, where I can display the description and title of that specific ID. My datbase is contains id, term_title and term_description.

I'm fresh outta the owen when it comes to PHP, but I've managed to atleast do this:

<?php
   $servername = "localhost";
   $username = "root";
   $password = "";
   $dbname = "dbname";

   $conn = mysqli_connect($servername, $username, $password, $dbname);

   if (!$conn) {
      die("Cannot connect to database." . mysqli_connect_error());
   }

   if (isset($_GET['id']))
   {
      $id = (int) $_GET['id'];
      $sql = 'SELECT * FROM dbname WHERE id = $id LIMIT 1 ';
   }

$sql = "SELECT * FROM terms";
$result = $conn->query($sql);

mysqli_close($conn);
?>

I'm really stuck and I dont know what the next step is, I've added the <a href='dictionary.php?=".$row["id"]."'> to each word I want to be linked, and this is properly displayed in the main index.php file (where all my words are listed with <li>. This is my code for this:

<?php
   if ($result->num_rows > 0) {
      while($row = $result->fetch_assoc()) {
      echo "<a href='dictionary.php?=".$row["id"]."'><li class='term'><h4 class='term-title'>" . $row["term_title"]. "</h4></li></a>";
   } else {
     echo "No words in database.";
   }
 ?>

How do I create this unique page, only displaying title and description for that id? How do I add ?word= to the url?

Thanks for taking your time to help me.

  • 1
    Not sure exactly what you are asking but if you are just wanting to append word to the query string something like this should work: `echo "
  • test

  • ";` – ajhanna88 Dec 01 '17 at 04:42