[英]How to access variable or variable value or variable on multiple PHP pages while continuously changing its value
I wanna to access in given scenario the the variable $i
as it is an incremented varaible which change value after an order. 我想在给定的情况下访问变量
$i
因为它是一个递增的变量,在定单后会更改值。 So how can i reuse it this in any other page. 因此,我如何在其他任何页面中重复使用它。 Morever tell me the that how can i use any "variable/varaible last value" on multiple pages without the session.
而且我告诉我,如何在没有会话的情况下在多个页面上使用任何“变量/变量最后值”。 And will session update the variable value when its change , if yes than how ?
并且会话将在变量值更改时更新它,如果可以的话? and There are many methods to do that ?
并且有很多方法可以做到这一点?
<?php include ('header.php');
if(isset($_POST['order']))
{
$user_id = $_SESSION['id'];
$date = date('Y-m-d H:i:s');
$username =$_SESSION['username'];
mysql_query("INSERT INTO tborder(user_id,`date`,username) VALUES('$user_id','$date','$username')") or die(mysql_error());
$i = mysql_insert_id();
if($i >0)
for($l=0;$l<count($_POST['product_id']);$l++)
{
$product_id = $_POST['product_id'][$l];
$quantity = $_POST['quantity'][$l];
$price = $_POST['price'][$l];
$discount = $_POST['discount'][$l];
$amount = $_POST['amount'][$l];
$username = $_SESSION['username'];
$user_id = $_SESSION['id'];
mysql_query("INSERT INTO tborderdetail(order_id,product_id,quantity,price,discount,amount,username,user_id) VALUES('$i','$product_id','$quantity','$price','$discount','$amount','$username','$user_id')")or die(mysql_error());
header('location:order.php');
}
}
?>
Cookies! 饼干!
By storing the variable value in a cookie each time the value is changed, you can use the variable on multiple pages throughout the domain. 通过在每次更改值时将变量值存储在cookie中,可以在整个域的多个页面上使用变量。
The cookie expiration time needs to be considered though, if the value is going to be there for a whole session, then storing it in a session cookie (until the browser is closed) will be useful. 不过,如果要在整个会话中使用该值,则需要考虑cookie的过期时间,然后将其存储在会话cookie中(直到关闭浏览器)会很有用。
Hope it helps! 希望能帮助到你!
how can i use any "variable/varaible last value" on multiple pages without the session.
我如何在没有会话的情况下在多个页面上使用任何“变量/变量最后值”。
PHP variables are "lost" between page requests, unless you store them in a session. PHP变量在页面请求之间“丢失”,除非您将它们存储在会话中。 If you don't want to use a session to store data there are many alternatives:
如果您不想使用会话来存储数据,则有多种选择:
And will session update the variable value when its change
并会在会话更改时更新变量值
Only if you store it in the session and update it. 仅当您将其存储在会话中并更新时。 Each time you set a new value in the
$_SESSION
array it'll persist across pages as long as the session is alive. 每次您在
$_SESSION
数组中设置一个新值时,只要会话$_SESSION
它就会在页面中保留。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.