Jump to content

Showing more/less text in loop


graham23s

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.