简体   繁体   English

如何从MYSQL数据库获取1条记录的ID,然后将其传递到详细信息页面以使用动态php和mysqli查看

[英]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 ie www.mysite/thejob.php?job_id=8 (the specific record details page). 我有一个html页面,列出了数据库中的所有作业,我设法使所有内容都显示在www.mysite / alljobs.php (或列出所有记录页面)上,很好,但是我无法从此页面获取不同的ID在动态链接上显示以显示每个作业的作业详细信息,即www.mysite / thejob.php?job_id = 8 (特定记录详细信息页面)。

I have recently had to upgrade my PHP version to PHP7 and need to use MYSQLI with PHP. 我最近不得不将我的PHP版本升级到PHP7,并且需要在PHP中使用MYSQLI。 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. 对于列表页面和详细信息页面所需的代码,我可以提供任何帮助,以便在我单击alljobs.php链接时创建动态页面。

如果对每条记录使用<a> ,则可以将id放在href中,如下所示:

<a href="www.mysite/thejob.php?job_id=<?php echo $id;?>"> Link </a>

您可以在PHP报价中使用echo传递您的id变量

<a href="www.mysite/thejob.php?job_id=<?php echo $id;?>">View</a>

You can loop over your query results and print out the ID for each one in a link, like this 您可以循环查询结果,并在链接中打印出每个ID的ID,如下所示

<?php
  foreach ($myQueryResults as $item){
?>

<a href="www.mysite/thejob.php?job_id=<?php echo $item->id;?>"> Link </a>

<?php
  }
?>

you can send the id on link url and the get with $jobID = <?php $_GET['id']?> on that page. 您可以在该链接网址上发送ID,并在该页面上发送$jobID = <?php $_GET['id']?>的get。 Don't forget to sanitize. 别忘了消毒。

<a href="www.mysite/thejob.php?id=<?php echo $jobId;?>">Details</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM