Jump to content

innerHTML == PHP ! Javascript


wyght

Recommended Posts

It has been ten years since I last wrote any code. I am trying to use PHP to write into a HTML element. I know JavaScript has the innerHTML function but I cannot seem to find any equivalent PHP function. My questions are

 

1) Is there an equivalent PHP function to innerHTML?

 

If not

 

2) Is there an intelligent method of using PHP fire JavaScript innerHTML

 

Why?

 

I want to get data from MySQL DB using PHP and print one record at a time to the webpage. I will be using a <div> tag as the data will be longer then one line so I do not want to use a span tag. I would like to force line breaks therefore I am using CSS with 'display:block;' I have not found a way to print the data from MySQL

Link to comment
https://forums.phpfreaks.com/topic/213680-innerhtml-php-javascript/
Share on other sites

It sounds to me like you could simply apply the HTML within your PHP instead of the other way around (although the other way around is possible as well).

 

EG1:

 

<?phpecho "<div style='display: block;'>";echo $result;echo "</div>";?>

 

 

EG2:

 

<?phpecho "<div style='display: block;'>";while ($row = mysql_fetch_array($result, MYSQL_NUM)) {   echo $row[0] . "<br>"}echo "</div>";?>

 

 

EG3:

 

<div style="display: block;"><?php echo $result; ?></div>

 

EG3:

 

<div style="display: block;"><?php while ($row = mysql_fetch_array($result, MYSQL_NUM)) {   echo $row[0] . "<br>"}?></div>

 

 

Maybe I'm misunderstanding?

with php you are assembling the output which happens to be html. Anything you echo out will get sent to the browser all at once which then parses it as html. So if you want something in an html element you echo it out in that element.

 

 

 <div id='whatever' class='yourclass'><!-- your mysql loop would go here --> </div>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.