How to add part of one PHP page to another?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Hi all.
There is a file index.php which through API retrieves the data and formed into a table and displayed. Is new.php to which you want to insert the table.
Prompt, please, as these things can be implemented.
by | 9 views

3 Answers

0 like 0 dislike
Isolate the table in a separate file / class / function.

For example:
Let it be a function, the output of which is html ready table. File getDataFromAPI.php contains the function getDataFromAPI().

And index.php and new.php include the file:
Get the html table and insert in the document:
<?php\r$table_html = getDataFromAPI();\recho $table_html;\r?>

More used to cache, probably a good thing.
0 like 0 dislike
In the right place of the file new.php:

include 'index.php';
0 like 0 dislike
in new.php:
include "index.php"; // if the page doesn't necessarily need a table, on error, gives a warning, but the script continues execution include_once "index.php"; // same as include, only the withdrawal is possible one time, will continue to pop up. require "index.php"; // if the page needs the table require_once "index.php"; // same as require, the only conclusion possible once. Further, if there is an error, the script will completely stop their work.
110,608 questions
257,187 answers
40,796 users