Search code examples
phpdatabasemysqlirecords

How to get the ID for 1 record from MYSQL database, then pass it to the details page for viewing using dynamic php & mysqli


I have a html page listing all the jobs in my database, I managed to get everything displaying on www.mysite/alljobs.php (or the list all records page), great, but I cannot get hold of the different id's from this page to display on a dynamic link to showing the job details for each job i.e www.mysite/thejob.php?job_id=8 (the specific record details page).

I have recently had to upgrade my PHP version to PHP7 and need to use MYSQLI with PHP. Can any help with the code I need for both the list page and the details page so that dynamic pages are created when I click on the alljobs.php links.


Solution

  • You can loop over your query results and print out the ID for each one in a link, like this

    <?php
      foreach ($myQueryResults as $item){
    ?>
    
    <a href="www.mysite/thejob.php?job_id=<?php echo $item->id;?>"> Link </a>
    
    <?php
      }
    ?>