简体   繁体   English

使用PHP和JQuery编辑HTML表模板

[英]Edit HTML Table template using PHP and JQuery

I have PHP code that fetches data from MySQL database and i want to place that data in table format in an already existing html template. 我有从MySQL数据库中获取数据的PHP代码,我想将这些数据以表格式放置在已经存在的html模板中。 I am currently doing it by putting html code in PHP echo. 我目前正在通过将HTML代码放入PHP echo中来实现。 I want to know if there is any better approach? 我想知道是否有更好的方法? What i thought of was i place a jquery in php and change the html code using 我想到的是我在php中放置一个jquery并使用以下方式更改html代码

$("").html();

but not sure how to add this jQuery script in my HTML as it is inside php? 但不确定如何在HTML中添加此jQuery脚本,因为它在php中?

It would be nice if you share with us what you have as of now. 如果您现在与我们分享您的财产,那就太好了。 To answer your question you can place jQuery script inside HTML using script tag. 要回答您的问题,您可以使用script标签将jQuery脚本放入HTML内。

Something like this: 像这样:

<script type="text/javascript">
$(document).ready(function() {

});
</script>

a way to do this using old trick in the current page use post 一种使用当前页面使用帖子中的旧技巧来做到这一点的方法

$.post('page.php', {want:'table'},function(return){
//show data on current page
show(return);
});

php side page.php php侧面page.php

<?php
   if(!empty($_POST['want']) && $_POST['want']==='table'){
   //fetch data from mysql
   $data=fetch_data();
   header('content-type: application/json');
   echo json_encode($data);
   exit(0);
   }
?>

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

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