Forum Moderators: coopster

Message Too Old, No Replies

dynamic tables with links

         

jortworx

8:31 am on Jun 15, 2005 (gmt 0)

10+ Year Member



Good Day!

Hope you could help! Can you please tell me or show how dynamic tables are created? Inside each cell contains links that if clicked, the table will expand downwards. ^_^ Is this possible?

Thank you guys!

Blackie

8:45 am on Jun 15, 2005 (gmt 0)

10+ Year Member



If I understand right what you are trying to get I would say php can not help here. You need CSS or JS to do that.

mincklerstraat

9:42 am on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed, css and javascript (combined in what people call DOM scripting - DOM = document object model) would be better than PHP if you really expect people to click on those 'expand it' links a lot. Using php would require initiating an extra page request.

Here's some code I lifted directly from one of my scripts, messy but works, that might get you started:


echo '&nbsp;&nbsp;<img src="i/plus.gif" style="cursor: pointer;" onclick="document.getElementById(\'row'.$i.'\').style.display=\'block\'; this.style.display=\'none\';" alt="show" title="show script info" id="plus'.$i.'">';
echo '<div id="row'.$i.'" style="display: none;">';
echo '<img src="i/minus.gif" style="cursor: pointer;" onclick="document.getElementById(\'row'.$i.'\').style.display=\'none\'; document.getElementById(\'plus'.$i.'\').style.display=\'inline\';" alt="hide" title="hide script info">&nbsp;&nbsp;';

Basically you make this part of your table-producing script, and with each row you increment $i, you make it do the code above, and then you output the content that you want hidden unless clicked, followed by a closing </div>. I just basically cut this out of the script so it might not work without tweaking, but if you are a bit familliar with js, it might give you the basic idea.

If you get more advanced in javascript you can actually attach events to specific elements so your HTML doesn't look so aweful as this; cleanier and nicer, but much more complicated programming.

If you go down this road, send your further questions to the javascript forum.

coopster

2:19 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sometimes it may require a round trip request to read new information from the server. That gets a bit more complex -- especially if there is naviational paging involved. However, from your description it sounds like you have a potential solution here from mincklerstraat.

Welcome to WebmasterWorld, jortworx.

mincklerstraat

4:52 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, indeed, if the page itself doesn't know ahead of time 'what' is to be displayed and is actually chosen on the basis of user input, you'll need php. You also may just choose to use php if you know php better than javascript. If you aren't comfortable with js I'd just go with php.

Btw. if you use the above code you'll want to put the whole thing inside a div so you can make the content initially hidden- eg.
<div id="hiddenpart">
(stuff here)
</div>
and in your css:
div #hiddenpart div {
display: none;
}