djinnov8 Posted September 21, 2010 Share Posted September 21, 2010 Hi everyone... I recently came across some jquery/js code that enables you to (toggle) showand hide a section of html code contained within a div... Now I am trying to do the same thing but with the results of a mysql query contained within PHP... so looking at sample code... $query = "SELECT first_name, last_name, comments from members" $result=mysql_query($query); if(mysql_num_rows($result) < 0) { echo "There are no members"; } else { while($rows = mysql_fetch_array($result)) { echo $rows['first_name'] . '<br />'; echo $rows['last_name'] . '<br />'; echo $rows['comments'] . '<br />'; } } How can I (toggle) show and hide the comments row for each individual member... Thanks for your reply in advance Quote Link to comment https://forums.phpfreaks.com/topic/214001-php-toggle-code-similar-to-javascript-toggle-div-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 21, 2010 Share Posted September 21, 2010 Php is a server side scripting language. It does not have the ability to do anything in the browser. It simply outputs content (HTML, Javascript, css, media files) to the browser when the browser makes http request to the web server. Perhaps if you define exactly what you mean by - How can I (toggle) show and hide the comments row for each individual member... Quote Link to comment https://forums.phpfreaks.com/topic/214001-php-toggle-code-similar-to-javascript-toggle-div-script/#findComment-1113675 Share on other sites More sharing options...
djinnov8 Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks for the reply...yes - as I mentioned in the post...show and hide the comments of each member similar to the javascript/jquery function.... I've seen this done on countless sites including (to some extent) Facebook...and Im guessing this is the clever use of javascript/jquery and html within the php code... Php is a server side scripting language. It does not have the ability to do anything in the browser. It simply outputs content (HTML, Javascript, css, media files) to the browser when the browser makes http request to the web server. Perhaps if you define exactly what you mean by - How can I (toggle) show and hide the comments row for each individual member... Quote Link to comment https://forums.phpfreaks.com/topic/214001-php-toggle-code-similar-to-javascript-toggle-div-script/#findComment-1113681 Share on other sites More sharing options...
djinnov8 Posted September 21, 2010 Author Share Posted September 21, 2010 Maybe I should've labelled this PHP toggle functionality similar to js toggle script (I've heard that you can break out of php midway through a statement or you could enclose key parts of the javascript script within (brackets) and echo other parts to get it to work within PHP code... This wouldn't work but I hope it lets you know what I'm after... <?php... { while($rows = mysql_fetch_array($result)) { echo $rows['first_name'] . '<br />'; echo $rows['last_name'] . '<br />'; ?> <script language="javascript"> function toggle() { var ele = document.getElementById("toggleText"); var text = document.getElementById("displayText"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "show"; } else { ele.style.display = "block"; text.innerHTML = "hide"; } } </script> <?php echo '<div id='toggleText' style='display: none'>'; echo '<h1>' . $rows['comments'] . '</h1></div>'; echo '<a id='displayText' href='javascript:toggle();'>show</a> <== click Here'; echo '</div>'; } } ...?> Quote Link to comment https://forums.phpfreaks.com/topic/214001-php-toggle-code-similar-to-javascript-toggle-div-script/#findComment-1113689 Share on other sites More sharing options...
djinnov8 Posted September 21, 2010 Author Share Posted September 21, 2010 I think I found something... http://www.webspeaks.in/2010/05/facebook-style-toggle-comment-box.html It utilises CSS, Jquery, HTML and PHP Quote Link to comment https://forums.phpfreaks.com/topic/214001-php-toggle-code-similar-to-javascript-toggle-div-script/#findComment-1113716 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.