graham23s Posted December 15, 2007 Share Posted December 15, 2007 Hi Guys, in my code i while loop out users blog posts, and have added a show/hide button for the text, but when im looping the blogs from mysql only the original show/hide button is working code: <script type="text/javascript"> function toggleBlock(id, linkid) { if (document.getElementById(id).style.display == 'none') { document.getElementById(id).style.display = 'block'; document.getElementById(linkid).innerHTML = '[HIDE BLOG]' } else { document.getElementById(id).style.display = 'none'; document.getElementById(linkid).innerHTML = '[sHOW BLOG]' } } </script> <?php ################################################# # viewblog.php ################################################# ## id $usersid = $_GET['id']; $query = "SELECT * FROM `usersblog` WHERE `bloggerid`='$usersid'"; $result = mysql_query($query); $blogcount = mysql_num_rows($result); ## no videos to display if($blogcount == 0) { ## echo a back link echo ("<div id=\"\" align=\"left\">[<a href=\"profile.php?id=$usersid\" class=\"foot_links\">Back To Users Profile</a>]</div>"); stderr("Error","This user has no blogs started yet."); include("includes/footer.php"); exit; } ## display the blogs while($row = mysql_fetch_array($result)) { ## vars $blogsubject = $row['blogsubject']; $blogtext = $row['blogtext']; $blogdate = $row['date']; echo ('<table class="sendmsgbox" width="500" border="1" bordercolor="#000000" cellpadding="5" cellspacing="0">'); echo ('<tr>'); echo ('<td colspan="2" class="header_boxes" align="left"><span class="colhead">Posted On: '.$blogdate.'</span> <a class="al" href="javascript:void(0)" onClick="toggleBlock(\'below\', \'linkid\');" id="linkid">[sHOW]</a></td>'); echo ('</tr>'); echo ('<tr>'); echo ('<td colspan="2" align="center"><div id="below" style="display:none; ">'.$blogtext.'</div></td>'); echo ('</tr>'); echo ('</table><br />'); } // end while loop ?> any ideas on what could be wrong? thanks guys Graham Quote Link to comment Share on other sites More sharing options...
emehrkay Posted December 15, 2007 Share Posted December 15, 2007 Yeah, ids are meant to be unique. All of yours are "below". You could easy fix that by adding an integer to then end of the below string like this $int = 0; while($row = mysql_fetch_array($result)) { $id = 'below:' . $int++; ... onClick="toggleBlock(\''. $id .'\' 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.