phpgoal Posted June 24, 2013 Share Posted June 24, 2013 Hello, I have a html table with 10 rows but I do not need 10 rows always. I want to see a number of rows depending on a value. That means during run time, if generated value is 2, i want to see only two rows. If generated value is 3, i want to see only three rows. How can i do that? -P Quote Link to comment https://forums.phpfreaks.com/topic/279527-dynamic-row-number-of-table/ Share on other sites More sharing options...
requinix Posted June 24, 2013 Share Posted June 24, 2013 Use a loop? Depends how you're doing things now - it's not like you've given us those kinds of details. Quote Link to comment https://forums.phpfreaks.com/topic/279527-dynamic-row-number-of-table/#findComment-1437700 Share on other sites More sharing options...
Psycho Posted June 24, 2013 Share Posted June 24, 2013 $max_rows = 3; for($row=0; $row<$max_rows; $row++) { // Insert code to create a row } Quote Link to comment https://forums.phpfreaks.com/topic/279527-dynamic-row-number-of-table/#findComment-1437701 Share on other sites More sharing options...
phpgoal Posted June 24, 2013 Author Share Posted June 24, 2013 Hello, I have the below code. Depending on the value of row, i want to see the same number of rows in the table. Can i do it? <script>Var row = 5</script> <table width='400' cellpadding='5' cellspacing='5' border='5' row = '5'> <tr> <td><b>Month/Year</b> </td> <td> <b>Income</b></td> <td><b>Expense</b> </td> <td><b>MK</b> </td> <td><b>MS</b> </td></tr> <tr> <td><p id="m0">Hello World!</p> </td> <td> <p id="i0">Hello World!</p></td> <td><p id="e0">Hello World!</p></td> <td><p id="k0">Hello World!</p> </td> <td><p id="s0">Hello World!</p> </td></tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/279527-dynamic-row-number-of-table/#findComment-1437709 Share on other sites More sharing options...
Psycho Posted June 24, 2013 Share Posted June 24, 2013 Can i do it? What part of the example I provided did you not understand? Put the code to create a row inside that loop. Put anything you need to display before those rows (e.g. the opening table tabs and headers) before the loop. And, put anything you need after those rows (e.g. the closing table tag) after the loop. Quote Link to comment https://forums.phpfreaks.com/topic/279527-dynamic-row-number-of-table/#findComment-1437719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.