0

I was wondering how I could add a scroll to my table that is written in the php file. I do not want to write it in a style.css file, I want it directly in the php file. below is my code, but I am not able to make it to work. The table gets content from mySql database, which works. but the problem is that I get to much of content so it fills out the whole page. That is why I want to make it scrollable :

if(mysqli_num_rows($result) > 0){ 
   echo '<table border="1">';
               echo "<tr>";
                   echo "<th>Name</th>";
               echo "</tr>";
   while($row = mysqli_fetch_array($result)){
    echo "<tr>";
         echo "<td>" . $row['name'] . "</td>";
    echo "</tr>";
           }
           echo "</table>";
9
  • If the page exceeds the browser window size, the browser will automatically add scrollbars. What exactly is the problem? Do you have CSS which is preventing that automatic behavior? Are you trying to do something else? Also, PHP has nothing to do with your client-side styling. That's entirely the HTML and CSS. Whether you want it to be or not. Commented Jan 24, 2018 at 18:30
  • you can only add scroll with css.you can add inline styling for that Commented Jan 24, 2018 at 18:33
  • @David the page exceeds the browser, but it does not add the scroll. I do now have any css at all Commented Jan 24, 2018 at 18:34
  • @Sikandar_ali I did try adding echo "<table <style> overflow-y: scroll; </style>>"; but it did not work Commented Jan 24, 2018 at 18:36
  • 1
    This has nothing to do with PHP or MySQL, and entirely to do with HTML and CSS. Commented Jan 24, 2018 at 18:41

1 Answer 1

1

If im getting your question right you need to set a width and height then set the overflow-y. This will give you a table set to a certain size with a scroll bar. Note you need to set your own width and height.

echo "<table style=\"width:500px; height:500px; overflow-y:auto\">"; 
Sign up to request clarification or add additional context in comments.

Comments

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.