I would like to be able to take data from a MySQL DB and place it in various div elements. I would like to do this after the page has been rendered. I know I could do this using JavaScript with innerHTML, but do not know what function to use in PHP. Please point me in the correct direction or show me the code.

Thanks

In JavaScript, something like this would insert "Hello World" into an element.

var element = document.getElementById('content');
element.innertHTML = "Hello World";

(Something like that...I'm not great at JS)

In PHP, it's made much simpler.

<div id="content">
<?php
$hello_world = "Hello World";
echo $hello_world;
?>
</div>

I feel stupid now. Thanks for your help.

I will have five div elements, I will use innerHTML and place them in the correct div. I thought I could use PHP but then looking at your reply I realized my error as PHP is in the server not on the client machine.

I want to get a dataset from a MySQL DB, then show one record at a time on the page's 5 div elements. What would I use to hold the dataset from the DB so I can access it using JavaScript.

Sorry I have been out of this for 6 years and am trying my best.

I would recommend using an AJAX query to a php file that could provide you with the data. A similar example is provided by W3Schools.

OK thanks this is great

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.