search

Home  >  Q&A  >  body text

How to return data to html after php queries the database

html
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Title</title></head><body><table border="1">
    <tr>
        <td>
            <?php
                echo$a;   #百度说这样可以,但我总是失败
            ?>
        </td>
    </tr></table></body></html>
php
<?php省略数据库查询;
$a = 123;?>

There is another situation

html
<!DOCTYPE html><html><head>
    <meta charset="UTF-8">
    <title>Title</title></head><body>
     <form>
     <input type="text">
     <input type="submit">   #代码简写了
     </form>
    </body></html>
    
php
<?php
省略数据库查询;
$a = 123;?>

I don’t know PHP, but I suddenly need to use it.

How to display the returned value in html after php queries the database.

After searching Baidu for a long time, I found that it didn’t work. .


We have reached the point where the ajax method is feasible. But if it is written in <script>, you can see it by directly viewing the code in the browser. How can I hide similar scripts and also achieve html php interaction?


What methods are you using now to implement html php interaction?

Thank you

辉€辉€2241 days ago2459

reply all(5)I'll reply

  • 虔

    2018-11-13 00:11:41

    Write a tpl file with a suffix name, then this tpl file is equivalent to an html file with a suffix name. Use PHP's object-oriented method to parse through regular expressions, and use PHP's caching mechanism to implement code that can be implemented without refreshing the browser. Data updates.

    reply
    0
  • 虔

    For example, {$name}, PHP's built-in variables in the HTML page are injected into _add("name", "Hello, PHP"). At this time, the HTML page will have the value of the injected PHP variable.

    · 2018-11-13 00:14:59
  • 天忆

    天忆2018-11-09 17:33:03

    When writing php code in an html file, you need to change the file suffix to php, or add the html format to parsing in Apache, otherwise it will not be parsed.

    reply
    0
  • 神沐

    神沐2018-11-09 11:04:28

    1541732566(1).jpg

    # Just embed the php code in the html

    reply
    0
  • 胤彬-

    胤彬-2018-11-09 09:25:47

    It’s been a long time since I wrote this kind of mixed HTML and PHP.

    Nowadays, the front-end and back-end are generally separated. The data queried by PHP is written out of the interface and returned in json form, and the front-end uses Ajax calls to obtain the data.

    reply
    0
  • Cancelreply