0

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

3
Contributors
4
Replies
9
Views
6 Years
Discussion Span
Last Post by vitaquous
0

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>

Edited by floatingDivs: n/a

0

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.

0

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.