Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add list items dynamically using PHP. But the code below does nothing.
According to me, everytime I refresh the page, a new list item should be created and displayed. But this isn't happening.

What I have tried:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<ul id="test">
<li>Sample</li>
<?php
$html = file_get_contents('index.php');
$doc = new DOMDocument();
$doc -> loadHTML($html);

$ul = $doc -> getElementById('test');
$li = $doc -> createElement('li', 'Test');
$ul -> appendChild($li);
?>
</ul>

</body>
</html>
Posted
Updated 22-Aug-17 6:38am
v2
Comments
Mohibur Rashid 22-Aug-17 22:24pm    
you did not print anything, you just have parsed the file. what do you expect?

1 solution

Every time you open the page, are you not opening the same file (index.php).

It has the same content every time you open it so it will do the same thing every time you open it.
 
Share this answer
 
Comments
Member 13037163 23-Aug-17 6:58am    
Any workaround to obtain the result?
W Balboos, GHB 23-Aug-17 14:44pm    
AJAX for your updates
Member 13037163 24-Aug-17 1:52am    
Thanks for the response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900