php - Data from database show/hide onclick trouble -
<?php $getnews = $db->prepare("select * news order id desc limit 4"); $getnews->execute(); $news = $getnews->fetchall(); foreach ($news $newspost) { echo $newspost['title'] ; ?> <a style="cursor:pointer;" onclick="return toggleme('problem')">read/hide</a> <?php echo '<br />'; echo 'posted '; echo $newspost["user"]; echo ' @ '; echo $newspost["created"]; ?> <div id="<?php echo $newspost['id']; ?>" style="display:none;"> <?php echo $newspost['message']; ?> </div> <?php echo '<br /> <br />'; } ?> what had in mind shows/hides text newspost when hit read/hide link next title of newspost.
can fit $newspost['id'] in representing div because onclick="return toggleme('problem')"> has both " , ' in need way fit in there, searched lot couldn't find looking for.
actually, you'll fine with:
"return toggleme('<?php echo $newspost['id']; ?>');" the inner single quotes never seen in output html, , <?php ?> block doesn't care quotes surround it.
Comments
Post a Comment