Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expand option to display further query details

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

I have a php script which calls messages from a database but I'd like to allow people to make a comments on the messages and view old comments by selecting a button which will expand to show all the comments made on a specific message:

Code to retrieve messages:
Code:
		$query1=mysql_query("select * from message order by timestamp desc" . " LIMIT $offset, $rowsPerPage");

			//echo $today;
				
			while ($row =@ mysql_fetch_array($query1)) {
				echo "<tr><td>"; 
				echo $row['message'];
				echo "</td><td>"; 
				echo "<tr><td>"; 
				echo $row['name'];
				echo "</td><td>";          
			        echo "<tr><td>"; 
				echo $row['timestamp'];
				echo "</td><td>";
				echo "<tr><td>";
				echo "<tr><td>.......................</td><td>"; 
			
			$messageid = $row['id'];

I've attempted this using a JS function which expands when selecting the "show all" button (i hard coded a message id to do this) but I don't seem to be able to merge the messages and the comments together.

Code:
<script type="text/javascript">
	function toggleMe(obj, a){
	var e=document.getElementById(a);
	if(!e)return true;
	if(e.style.display=="none"){
	e.style.display="block"
	obj.firstChild.data='Hide all';
	} else {
	e.style.display="none"
	obj.firstChild.data='Show all';
	}
	return true;
	}
</script>

<div id="showhide1" style="display: none;">
	$query1=mysql_query("SELECT comment, name, timestamp FROM comments WHERE id=$messageid");

						
			while ($row =@ mysql_fetch_array($query1)) {
			             			            			
			 echo "<tr><td>"; 
				echo $row['message'];
				echo "</td><td>"; 
				echo "<tr><td>"; 
				echo $row['name'];
				echo "</td><td>";          
			        echo "<tr><td>"; 
				echo $row['timestamp'];
				echo "</td><td>";
				echo "<tr><td>";
				echo "<tr><td>.......................</td><td>"; 	
			
}
?>
	<form name="update" action="insert_comment.php" method="post">
     		<table>
        		<tr>
          			<td> Comment: </td>
          			<td><textarea rows="2" cols="30" name="message" onchange="this.value=validated(this.value)"></textarea></td>
        		</tr>
        		<tr>
          			<td>Name:</td>
          			<td><input name="name" type="text" onchange="this.value=validated(this.value)" /></td>
        		</tr>
        		<tr>
          			<td><input name="add_button" type="submit" value="Update" /></td>
        		</tr>
      		</table>
   	 </form>

</div>
<a href="#" onclick="return toggleMe(this, 'showhide1')">Show all</a>

Does any one know how to easily do this?

Thanks in advance!
 
Your Javascript works fine for me, however, its likely not working, because your comments table starts somewhere outside the div you are showing an hiding. And it also never seems to end, as you start a new table before closing the one you are generating with you PHP code.

Try moving the entirety of your table inside the DIV. Or Better yet, Add <table> </table> tags inside the DIV to correctly open and close the table you are generating with from your DB

With that said, this is neither a JS nor a PHP issue, but an HTML one. Where bad HTML coding leads to unexpected results.
You can easily confirm this by looking at the rendered code, once all PHP has been parsed.

forum215




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top