反正有什么要携带价值在php转发到第二页? [英] Is there anyway to carry a value in php forward to a second page?

查看:55
本文介绍了反正有什么要携带价值在php转发到第二页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个php网站,以前它仅列出具有定义值的产品。我现在将其更改为包括一系列产品,例如所有产品WHERE id = spotlights

I have created a php site, and previously it was listing only products with defined values. I have now changed it to include an array of products for example all products WHERE id = "spotlights"

,它的效果很好,因此我可以将新产品添加到数据库,但我仍然必须手动添加第二页。例如,从主页上的产品div到www.example.com/spotlight_1.php

and this works great so it means I can add new products just to the database, but I still have to add the second page manually. e.g going from the product div on the main page, through to www.example.com/spotlight_1.php

PHP中是否总有一些数据可以承载我的索引中的数据。 PHP的例如该ID到下一页?这样我就可以拥有一个模板product.php页面,并且可以使用数据库请求来回显所需的产品信息。

Is there anyway in PHP to carry the data from my index.php e.g. the ID through to the next page? so that I can have a template product.php page, and I can use a database pull to echo the product information required.

在index.php上,我单击带有ID = 1的产品,并在product.php页面上,它会加载产品1的相关数据。

So on index.php i click on the product with ID="1" and on the product.php page, it loads the relevant data for product 1.

我可以自己编写php SQL / mySQL调用,

I can write the php SQL/mySQL calls myself, its just the way to carry accross a value from the previous page which I dont understand

问候

Henry

ps
所有ID和事物已作为1到3位数字值存储在数据库中,例如3或93或254

p.s. all the IDs and things are stored in the database already as 1 to 3digit values e.g. 3 or or 93 or 254

任何建议一如既往地受到赞赏

Any advice as always is greatly appreciated

致谢

Henry

推荐答案

im不知道im是否正确理解了该变量,但是可以从

im not sure if im understading this correctly but you can pass the variable from one page to another using GET variables, or in other words, using the query string in the URL.

因此,在index.php中,您将具有这样的链接:

So, in index.php you will have links like this:

<a href="product.php?p=1">Product 1</a>

在第二页(product.php)中,您可以使用以下代码获取此变量:

In the second page (product.php) you can get this variable using this code:

$product_id = $_GET['p'];

然后像这样查询数据库:

And then query your database like this:

$query  = "SELECT * FROM products WHERE id = '" . $product_id . "'";
$result = mysql_query($query);

参考: http://www.w3schools.com/php/php_get.asp

注意:请谨慎使用查询您的数据库时,前面的代码仅是如何检索信息的演示,而不是安全的解决方案。我建议您检查PDO(http://php.net/manual/es/book.pdo.php)。

Note: Be careful with the way you query your database, the previous code is only a demonstration of how to retrieve the info, but is not a secure solution. I recommend you to check PDO (http://php.net/manual/es/book.pdo.php).

这篇关于反正有什么要携带价值在php转发到第二页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆