2

UPDATE: I just realized that I'm too noob for javascript and jquery, thanks for answering my questions! How do I close this question?

I'm using PHP and MYSQL for the database, I want to display my database's row values to a but the thing is what if I have like 1000 rows, it'll be really useful If there is a table that doesn't expand as your data floods it with details but instead gives you a scroll option to view the other rows. Please help me, I really have no idea how to do it...

I do know how to connect to my database and to output it but I don't know how to make a table that is scroll-able and does not expand but instead gives you scroll just like a browser...

<?php

mysql_connect('localhost','root','');
mysql_select_db('database');

$query = 'SELECT * FROM table';
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){
echo $row['name'],' ',$row['lastn'],'<br>';
}

?>
4
  • You need some JavaScript for that. Have a look at JQuery and Datatable. Commented Feb 24, 2015 at 17:22
  • i don't understand the difference between javascript and php, i mean the both of them can use and declare functions, can't i just use php instead of javascript? Commented Feb 24, 2015 at 17:26
  • PHP is executed on the server. JavaScript is executed on clientside. What you need is a client side (browser side) solution, if you want a scrollable table. Commented Feb 24, 2015 at 17:31
  • thank you a lot for explaining that!!! Commented Feb 24, 2015 at 17:42

1 Answer 1

2

Hello!

Use DataTables to accomplish this easily.

First, initialize your table with jQuery:

$(document).ready(function() {
$('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "..phpFileAjaxReturn.php"
} );

} );

In this file "phpFileAjaxReturn.php", you should use PHP to make a SELECT on your database and return the values.

You should use echo json_encode( $output ); to send the Data Correctly to the Table.

Look at these links:

https://legacy.datatables.net/examples/data_sources/server_side.html https://datatables.net/examples/api/tabs_and_scrolling.html

Sign up to request clarification or add additional context in comments.

6 Comments

You may want to put the actual answer into your post & use the link only for support.
thanks for that but this javascript and jquery to me is something new and it's confusing me a lot, is there any video that can show me how to use that?
Well... If you want to be a web developer, javascript is very, very important for almost everything. Have a look at this link that lists the bests websites to learn code online. hongkiat.com/blog/sites-to-learn-coding-online <-- Most of them have javascript and jQuery lessons. Its a good start.
upvoted! thanks for the help! but for now i'll just use a simple <table>, i'll study jquery and javascript first then tackle this topic again for maybe after a very long time, thanks really appreciated it!
@Guilherme, thanks for that source materials! I'll study it right away.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.