doumen6532
2015-06-27 11:15
浏览 47
已采纳

将php生成的数据发送到html元素

Lets say I have html page that has 3 elements. Content of those elements should be taken from data base and just put there. Now, I can take data from db, I made my html and css styling, only problem I have is I don't know how to update html page with php data taken from Db. I don't want to use echo since that will give me separate page, I thought about using php to open that html file and rewrite it dynamically but that seems bit extreme. Any suggestion ?

图片转代码服务由CSDN问答提供 功能建议

假设我有html页面有3个元素。 这些元素的内容应该从数据库中获取并放在那里。 现在,我可以从db获取数据,我制作了我的html和css样式,只有我遇到的问题是我不知道如何使用从Db获取的php数据更新html页面。 我不想使用echo,因为那会给我单独的页面,我想到使用php打开那个html文件并动态重写它,但这似乎有点极端。 有什么建议吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dou8mwz5079 2015-06-27 11:21
    已采纳

    Make the extension of your html page as .php Where you want to put data do something like this -

    <?php
        // write your select query
        $val = "data retrieved from php"
    ?>
    

    Where you want to place it in the DOM, do something like this -

    <div><?=$val?></div>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题