Title: Add rows in a html file from an external php file
Tags: javascript;php;html
Question: I'm trying to find how to insert a row line to a table in html so , but i would like to do it using an external php file, but maybe another solution because the purpose is to get a table from a database one and write it down to an html table.
i've tried to look on the internet but i didn't find something that was fitting with what i was lookin for.
Comment: Hi, and welcome to SO.  Your question is a difficult to understand and you have not provided any examples of what you have tried, what the output was and how this is different what what you had expected.

Comment: i haven't tried something that has given me a result, but the question is if exist a way to write down a database table in html table. I'm new on these things i've just started programming in html and php sorry :)


Here is another answer: Do you mean some thing like "example 1" from here (https://www.php.net/manual/en/mysqli-result.fetch-assoc.php)?
You only need to add the html tags to create the html table (table, td, ...).
This example includes the html tags and should do what you want:
<html&gt;
<body&gt;
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "database");
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = $mysqli-&gt;query($query)) {
echo "<table&gt;";
/* fetch associative array */
while ($row = $result-&gt;fetch_assoc()) {
echo "<tr&gt;<td&gt;" . $row['Name'] . "</td&gt;<td&gt;" . $row['CountryCode'] . "</td&gt;</tr&gt;";
}
echo "</table&gt;";
/* free result set */
$result-&gt;free();
</body&gt;
Comment for this answer: I added the complete example with html tags.
Comment for this answer: You need to initial $mysqli. I will add it.
Comment for this answer: I edit my answer. I prefer separating html and php but this should do it.
Comment for this answer: Welcome to StackOverflow! While this link may answer the question, it is better to write down the essential parts as a short conclusion and provide the link for reference. Link-only answers can become invalid if the linked page changes or is no longer reachable.
Comment for this answer: yes but how can i share those data to an external html file in this way i'll get just the data from the database
Comment for this answer: it returns to me this error :    Fatal error: Uncaught Error: Call to a member function query() on null in /Library/WebServer/Documents/serverConnectionAndStore/phps/getElement.php:8 Stack trace: #0 {main} thrown in /Library/WebServer/Documents/serverConnectionAndStore/phps/getElement.php on line 8 .
Comment for this answer: oh yes i did it but i need to use the data inside the html code so not just to display the table i would like to have something like this. `   " data obtained from database" </body `
Comment for this answer: maybe we misunderstood each other but i would like to separate html and php so maybe what i'm wondering is impossibile or not logical i would like to share those data using some trick i'don't know maybe passing them to a js file and than by the js putting them in the html file using something like https://www.w3schools.com/jsref/met_table_insertrow.asp

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:06/24/19', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<javascript><php><html>', 'Title': 'Add rows in a html file from an external php file', 'ViewCount': 90, 'id': 56732282, 'user_AboutMe': None, 'user_AccountId': 14970434.0, 'user_DisplayName': 'damiano shushku', 'user_Reputation': 1.0, 'user_Views': 4.0, 'user_id': 10807487.0}}