r/backtickbot • • Dec 29 '20

https://np.reddit.com/r/PHPhelp/comments/kmir0v/question_about_mixing_php_and_html/ghet5fl/

that is not "illegal" - you are probably referencing vars that the ide doesn't know is from databasequery, so throwing some errors makes sense

but to be clear, this is not modern or recommended.

ideally your php page would do the processing, then include html file.

  • rename databasequery.php to Query.php and make it OOP like

  • move your html file to a templates dir and name it to describe what it presents. for example templates/main.html

    class Query { public function getData() { ...get the data from sql } }

then your php page would get the result from that class and then require the html file

<?php
require("Query.php");
$query = new Query();
$data = $query->getData();
require("templates/main.html");

then finally in your main.html you have access to the $data var so you can display it

...html...
<?php echo $data; ?>
...html...
1 Upvotes

0 comments sorted by