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.


7 Years
Discussion Span
Last Post by vitaquous

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">
$hello_world = "Hello World";
echo $hello_world;

Edited by floatingDivs: n/a


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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.