2013-06-05 156 views
-1

我正在将timestamp=now()从一个页面显示到另一个页面。我怎样才能通过这个功能?至于第二页,我想根据timestamp=now()检索表格。我已经这样做了,但它不起作用。请帮助我。如何将Now()函数从一个页面传递到另一个页面php

编码

<script type="text/javascript" charset="utf-8"> 
function showCustomer(n) 
{ 
var xmlhttp;  

if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
    {// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    document.getElementById("display").innerHTML=xmlhttp.responseText; 
    } 
    } 

    alert(n); 
xmlhttp.open("POST","display.php?id="+ n,true); 
xmlhttp.send(); 

} 

</script> 

</head> 

<body> 
<form> 
<?php $s= 'now()'; 
echo $s; ?> 
<input type="button" value="h" name="s" onclick="showCustomer(<?php $s ?>)"> 
<div id='display' > 
<?php 
echo "111"; 

?> 
</div> 

我通过这个编码从数据库中检索数据:

<?php 
include('config.php'); 
$sa="select * from table1 where timestamp=now()"; 
$result=mysql_query($sa) or die(mysql_error()); 
echo "<table border='1'> 
<tr> 
</tr>";?> 
<?php 
while($row = mysql_fetch_array($result)) 
{ 
    $row['c1']; 
    $row['c2']; 
    $row['c3']; 
     $row['c4']; 
} 

我必须还要考虑Now()函数调用上翻页按钮点击此表。请帮助我。

+0

请以与传递ID相同的方式将now()作为GET参数传递。 – RGV

+0

字符串必须在js中引用 –

+0

仅供参考:mysql_'查询已弃用并打开SQL注入。改为使用'mysqli'。 –

回答

1

假设你的目标是要保存一些时间戳:使用会话为

session_start();//in every file (in which you want to access sessions) as first statement before any output 
//set time 
$_SESSION['now'] = date("Y-m-d H:i:s"); //mysql datetime format 
//read time 
$save_time = $_SESSION['now']; 
+0

先生我需要在javascripting中进行更改 – user2444690

+0

如果这是一个问题,我会说:你可以删除js中的所有内容,这些内容可以在'now'上运行/因为你通过纯代码处理这个代码。 – luk2302

+0

sir其不工作就像点击它想要显示的按钮 – user2444690

0

我想你错过了echo在这个声明<input type="button" value="h" name="s" onclick="showCustomer(<?php $s ?>)">

请!覆盖与<input type="button" value="h" name="s" onclick="showCustomer(<?php echo $s ?>)">

+1

也应该有效。 – nderscore

+2

是的,但只有当他在php.ini文件中启用'short_open_tag = On'时:-)。 –

+2

@nderscore它只有在打开short_tags时才会有效,否则会出错 –

0

此行没有php Now()函数是一个mysql功能,如果你想要的是MySQL的NOW()回报

你必须使用PHP的date("Y-m-d H:i:s");在这里这种格式是参考date相同的值

<?php $s= date("Y-m-d H:i:s"); 
echo $s; ?> 
+0

先生我在$ s中获取日期如何将此日志传递给javascripting – user2444690

相关问题