简体   繁体   English

如何传递从URL获取的ID值并将其传递给PHP

[英]How to pass on id value fetched from url and pass it in php

My Page url is 我的页面网址是

http://www.example.org/index.php?option=com_used&prid=100&id=200
http://www.example.org/index.php?option=com_used&prid=100&id=201
http://www.example.org/index.php?option=com_used&prid=101&id=202
http://www.example.org/index.php?option=com_used&prid=99&id=203

Here id is unique field name id是唯一的字段名称

I have below code to display mobile number of seller for field column where a used toy listing id is mentioned 我在下面的代码中显示了提及二手玩具清单ID的字段列的卖方移动电话号码

$db = JFactory::getDbo();
$db->setQuery("SELECT `mobile` FROM `#__used_variants` WHERE `id`='200' LIMIT 1");
return $db->loadResult();

I am unsure how to capture in id field value from url and pass in php code, so that when page id is 200 then mobile number of seller having id as 200 is shown, and wen page is 201, seller having id as 201 is shown, same for 202 and 203 and so on 我不确定如何从url中捕获id字段值并传递php代码,因此,当页面id为200时,将显示id为200的卖方的移动电话号码,而温页为201,则将id为201的卖方显示,与202和203相同,依此类推

Can any one help in in 谁能帮忙

You can get parameters in PHP using $_GET . 您可以使用$_GET在PHP中获取参数。

Try this: 尝试这个:

  echo $_GET['id'];

It will return the id from url. 它将从网址返回ID。

So you can try this: 因此,您可以尝试以下操作:

 $id = $_GET['id'];

 $db = JFactory::getDbo();
 $db->setQuery("SELECT `mobile` FROM `#__used_variants` WHERE `id`='$id' LIMIT 1");
 return $db->loadResult();

The $_GET holds the parameters passed via url. $ _GET保存通过url传递的参数。

use $_GET['id'] to access the id parameter 使用$ _GET ['id']访问id参数

$db->setQuery("SELECT `mobile` FROM `#__used_variants` WHERE `id`=".$_GET['id']." LIMIT 1");

Ensure that you escape the $_GET['id'] parameter to prevent SQL injection 确保转义$ _GET ['id']参数以防止SQL注入

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

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