简体   繁体   English

每次单击一个按钮,将PHP变量更改1036800。

[英]change a PHP variable by 1036800 each time a button is clicked.

This is a bit from the query, a roster type database is looked at comparing current user and obtains data from the database. 这是从查询中得出的一点,查看了一个名册类型的数据库以比较当前用户并从该数据库中获取数据。 It always starts with today's date and ends 12 days later using unix time. 它始终以今天的日期开始,并以Unix时间结束12天。

<?php
$INQID = $member->userID();
$loc = $member->UserLocation();
$range_start = time();
$range_end = $range_start + 1036800;
$username = "******";
$password = "******";
$hostname = "******";
$dbhandle = mysql_connect($hostname, $username, $password)
             or die("Unable to connect to MySQL");
$selected = mysql_select_db("DATABASE",$dbhandle)
             or die("Could not select DATABASE");
$result = mysql_query("SELECT username, date, state FROM ".$loc."  WHERE username
=$INQID  and date > $range_start and date < $range_end");
$result_array = array();

My question is how can I add a button to move the start date forward or back by 10368000 (twelve days unix time) which in turn will move the end date, showing the user the next 12 days. 我的问题是如何添加按钮将开始日期向前或向后移动10368000(统一时间十二天),这又将移动结束日期,向用户显示接下来的12天。 while preserving the start date when the user logs in? 同时保留用户登录的开始日期? I would like to stick with unix time as the shifts cover 24 hours so it is easier for me to use. 我希望坚持使用unix时间,因为轮班时间为24小时,所以我更容易使用。

  <div id="Rbutt">
<a href="#" class="Rbuttons">Next</a>
</div>
<div id="Lbutt">
<a href="#" class="Rbuttons">Back</a>
</div>

I have two buttons left(-) and right(+) I would like to use however changing these is not a issue. 我想使用两个按钮left(-)和right(+),但是更改这些不是问题。

您可以在mysql表中添加时间戳并更新值,每次都获取该值并使用

Try something like the following: 尝试如下操作:

<?php

$INQID = $member->userID();
$loc = $member->UserLocation();
$range_start = time();
if(isset($_POST['timeRange'])) {
    $range_end = $range_start + $_POST['timeRange'];
}
else {
    $range_end = $range_start + 1036800;
}
$username = "******";
$password = "******";
$hostname = "******";
$dbhandle = mysql_connect($hostname, $username, $password)
             or die("Unable to connect to MySQL");
$selected = mysql_select_db("DATABASE",$dbhandle)
             or die("Could not select DATABASE");
$result = mysql_query("SELECT username, date, state FROM ".$loc."  WHERE username
=$INQID  and date > $range_start and date < $range_end");
$result_array = array();

With the following HTML code: 使用以下HTML代码:

<form action="filename.php" method="post">
    <input name="timeRange" type="hidden" value="1036800" />
    <input type="button" class="Rbuttons" value="next" />
</form>

<form action="filename.php" method="post">
    <input name="timeRange" type="hidden" value="-1036800" />
    <input type="button" class="Rbuttons" value="back" />
</form>

Unfortunately I haven't tested the above code (so I hope it's right and actually works!) regardless, I think this should help point you in the right direction. 不幸的是,无论如何,我都没有测试过上面的代码(因此,我希望它是正确的并且可以正常工作!),我认为这应该可以为您指明正确的方向。

Obviously the input should be sanitized, but I'll leave that to you. 显然应该对输入内容进行清理,但我将留给您。

Solved using the following thanks for all answers which pointed me in the correct direction. 使用以下命令解决了所有为我指明正确方向的答案。

<?php
$INQID = $fgmembersite->userID();
$loc = $fgmembersite->UserLocation();

$FwdBck = $_GET["FwdBck"];
if ($FwdBck =="")
{
        $FwdBck = 86400;
}
$start = time();
$range_start = $start - $FwdBck;
$range_end = $range_start + 2419200;
$username = "******";
$password = "******";
$hostname = "******";
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");
$selected = mysql_select_db("DATABASE",$dbhandle)
  or die("Could not select DATABASE");
$result = mysql_query("SELECT username, date, state FROM ".$loc."  WHERE username=$INQID       and date >$range_start and date <$range_end");
$result_array = array();

And the buttons 和按钮

     <div id="FwdWeek">
     <form method="GET" action="<?php echo $PHP_SELF;?>">
     <input type="hidden" name="FwdBck" value="<? echo $FwdBck-(7*86400) ?>">
     <input class="Rbuttons" type="Submit" value="> Week">
     </form>
     </div>
     <div id="BkWeek">
     <form method="GET" action="<?php echo $PHP_SELF;?>">
     <input type="hidden" name="FwdBck" value="<? echo $FwdBck+(7*86400) ?>">
     <input class="Rbuttons" type="Submit" value="< Week">
     </form>
     </div>

and associated CSS for styling 和相关的CSS样式

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

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