-1

I'm new to the PHP Programming and I have a problem with dynamic urls. I load images from the database (in a row) and I want to make them dynamic urls, that redirect to the same page. The problem is that this page must have different ID for each image, but when i try it only the first image redirect and has wrong ID. Can somebody help?

This's the code I use.

<?php
  if(isset($_GET['ID'])) {
  require_once 'connection.php';
  $ID = mysqli_real_escape_string($con, $_GET['ID']);
  
  $link = "SELECT * FROM books";
  $resultlink = mysqli_query($con, $link) or die("Bad Query: $link");

  $image_query = "SELECT * FROM bookscategory, books WHERE idc='$ID' AND 
  (idc=idcateregory AND idnewpop=1)";
  $result2 = mysqli_query($con, $image_query) or die("Bad Query: 
  $image_query");
  $row2 = mysqli_fetch_array($result2);
  }

  else {
  header ('Location: ..\Index.php');
  }
  ?>


<?php
do {
 if(mysqli_num_rows($resultlink) > 0) {
     do {
      echo"<a href='Book.php?ID={$rowl['idBook']}'></a>";
    } while($rowl = mysqli_fetch_array($resultlink));
  } else {
    echo"<No Link>";
  } 
echo '<img alt="_" width="115" height="170" class="bookImage" src="'.$row2['img_dir'].'" />';
} while($row2 = mysqli_fetch_array($result2));
 ?>
  • Can you rephrase your question without the word `dynamic`? If you know how to do it for 1 image (see: https://stackoverflow.com/questions/31793512/php-display-image-from-url-into-homepage), then I do not see the problem how to do it `dynamically`.... – Luuk Jun 13 '21 at 17:02

1 Answers1

0

You can use $_GET[]

$_GET will be visible in the url , using $_GET is very easy you just need to add ? at the end of the url

Exaple like this

site.net/page.php?ID=h1

$_GET['id'] will contain 1

Apply like this

HTML

<a href="page.php?ID=1">
    <img src="....">
</a>
<a href="page.php?ID=2">
    <img src="....">
</a>

page.php :

<?php
if(isset($_GET['ID'])){
echo"<h1>You Inside Image ".$_GET['id']."</h1>";
}
il4mb
  • 105
  • 1
  • 5