wyght Posted September 17, 2010 Share Posted September 17, 2010 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 Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 17, 2010 Share Posted September 17, 2010 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? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted September 17, 2010 Share Posted September 17, 2010 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> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 17, 2010 Share Posted September 17, 2010 Another note: divs are displayed as block by default. You don't need to do anything with CSS to get that functionality. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.