简体   繁体   中英

how to get id from URL using php

I have this code on my Search page:

<a href="detail.php?id=<?php echo $ido;?>"STYLE="TEXT-DECORATION: NONE"><?php echo $nume;?></a>

and i also have a detail.php page. I need to get the $ido value from the URL so that I can use it in the detail.php page to retrieve information from the database.

The detail page has a URL like this: detail.php?id=17 , I need to get the value after the = , in this case 17 , into a variable.

In your detail.php use: $id = $_GET['id']; you can then use $id around the rest of your page.

You can also use $_SERVER['QUERY_STRING'];

But this will only fetch id=17

If still having problem then try:

  • To fetch integer value:

     $id = intval($_GET['id']);
  • To fetch string value:

     $name = strval($_GET['name']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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