0

hi there, i want to display my data coming from database..i could do that using a table, however the problem is that the table will just expand everytime there is data. what i want to have is a control which has a scrollbar which will display lots of data.

i've heard of the datagrid in php, however, i cannot apply it., could you give me the simplest one? thanks..

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by CJesusSaves
0

Well, you can put the table in DIV containers and style it like:

<div style="height:200px; overflow:auto;">
<table>
<tr>
<th></th>
</tr>
<?php
//Table looping rows here
?>
</table>
</div>

The overflow sets scrollbars only when the data surpasses the height of the table. The method works in IE5.5+ so I guess that's good news.

Or you can implement pagination. :) Look here:
http://www.phpeasystep.com/phptu/29.html or Google for more.

0

mam, the code works very well, but what if i want the inner table to be adjustable, i mean, the size of the table will depend on the text..

0

I'm having a hard time understanding your previous question as it seems somewhat ambiguous. Adjustable by whom, the programmer or the user? What do you want to be adjustable? Using the above example, the height of the table cannot be adjusted beyond the scope height of the DIV's. So it is best that just the height of the DIV is adjusted, and the table will auto expand to fixed size.

For the programmer, this is no problem, just predefine to a suitable height.

For a user, there would probably need to be 2 links or so, one that when clicked, makes the height of the DIV taller and another to make shorter.

Example, these text links may be put above or below the table:

<a href="myPage.php?h=<? echo $height; ?>&th=t" title="taller">+</a>
<a href="myPage.php?h=<? echo $height; ?>&th=s" title="shorter">-</a>
<?php 
$height = $_GET['h']; // get current height

if ($_GET['th'] == "t")
$height += 100; //make taller

if ($_GET['th'] == "s") 
$height -= 100; //make shorter

?>

<div style="height:<?php echo $height; ?>px; overflow:auto;">
<table>
<tr>
<th></th>
</tr>
<?php
//Table looping rows here
?>
</table>
</div>

If one were to link to the myPage.php from another source, an example of such would be:

<a href="myPage.php?h=200" title="My Page">Go to myPage</a>

the size of the table will depend on the text

Depends on what properties of the text? The font properties or text quantity?

You can of course style the table and it's text with CSS.

http://www.w3schools.com/Css/default.asp

0

hi there sir, i already got it..thanks for your wonderful help..this code is really great..^_^

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.