从 PHP 访问 html 表
我真的很难从 PHP 访问我的 html 表。
这就是我所拥有的:
file.php
<?php
...some php code
$someValue = '2012';
?>
<script language='javascript'>
var table = document.getElementById('tableId');
for (var i = '<php echo $myVar?>',row; row = table.rows[ '<php echo $myVar?>']; i++) {
//iterate through rows
//rows would be accessed using the 'row' variable assigned in the for loop
for (var j = 0, col; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the 'col' variable assigned in the for loop
col.innerHTML = '<?php $someValue; ?>'
}
}
</script>
<?php
... continue php codes.
?>
我在这里有意义吗?我想将 $someValue
放置到我的表格单元格中。
帮助
流程是这样的...我有
file-1.php
- 包含我的表
- 包含 file-1.js
file-1.js
- 有一个执行 file-2.php 的 ajax 对象,
然后我想要 file-2.php访问 file-1.php 中的表 并使用 file-2.php 中生成的值填写单元格
I'm really having a hard time with accessing my html table from PHP.
This is what I have:
file.php
<?php
...some php code
$someValue = '2012';
?>
<script language='javascript'>
var table = document.getElementById('tableId');
for (var i = '<php echo $myVar?>',row; row = table.rows[ '<php echo $myVar?>']; i++) {
//iterate through rows
//rows would be accessed using the 'row' variable assigned in the for loop
for (var j = 0, col; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the 'col' variable assigned in the for loop
col.innerHTML = '<?php $someValue; ?>'
}
}
</script>
<?php
... continue php codes.
?>
Do I make sense here? I wanted to place the $someValue
to my table cell.
Help
The flow is something like this... I have
file-1.php
- contains my table
- contains file-1.js
file-1.js
- has an ajax object that executes file-2.php
then I wanted file-2.php to access the table in file-1.php
and fill out the cells with the values generated in file-2.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要回显该变量。
You need to echo that variable.
您只是忘记
回显
它了。You simply forgot to
echo
it out.当您使用 ajax 时,以 json 形式 (http://www.json.org/) 从 file2.php 发送新值,例如尝试这个 ( http://www.itnewb.com/tutorial/Introduction-to-JSON-and-PHP)
然后使用 javascript 获取每个 json 值然后你就可以更新你的 html 表。
最好使用一些 javascript 库,例如 Jquery ( http://www.jquery.com/ ),这样你就可以轻松做到这一点
As you are using ajax, send the new values from file2.php in a json form (http://www.json.org/) for eg try this ( http://www.itnewb.com/tutorial/Introduction-to-JSON-and-PHP)
Then use javascript to get the json values each and then u can update ur html table .
Better use some javascript libraries like Jquery ( http://www.jquery.com/ ) , so that u can do this easily