tsuchijun Posted November 2, 2011 Share Posted November 2, 2011 I am trying to create something similar to a bar chart, using a html table based on the values stored in an array. However, I cannot seem to get the next column to begin after printing the number at the bottom. I can get it going horizontal, but I would like to create a vertical version. If anyone can provide me with help I would greatly appreciate it. <?php $month = date("n"); //numeric representation of month (1-12) $year = date("Y"); //4 digit representation of year $day = date("d"); //numeric representation of the day of the month // constant variable to determine how many days alive according to the current date define('DAYS_ALIVE',(($year - 1902) * 365.24) + (($month - 1) * 30.5 )+ ($day - 1)); $divident = 100000; // variable for modulus $divider = 10000; // variable to shrink the divident for($i = 0; $i <= 4; $i++) // for loop to fill the array with days alive { $daysArray[$i]= floor((DAYS_ALIVE % $divident)/$divider); //calculates the single digit to store in array $divident= $divident/10; //after every iteration the divident is decreased $divider= $divider/10; //after every iteration the divider is decreased } echo "<table border='2' width='100%'>"; $arraySize = count($daysArray); //variable for the array size for($k=0;$k<=$arraySize-1;$k++) { echo "<tr>"; for($j=1;$j<=$daysArray[$k];$j++) { echo "<td> * </td>"; } echo "<td>$daysArray[$k]</td>"; } echo "</table>"; ?> What I want is something like this. Quote Link to comment https://forums.phpfreaks.com/topic/250334-help-creating-a-vertical-table-chart/ Share on other sites More sharing options...
freelance84 Posted November 3, 2011 Share Posted November 3, 2011 Here you go. That should work. Although.... was this your code? If yes, then you shouldn't use html border or width. Use CSS. I also changed your for loops. You could also achieve a nice result with div heights as percentages or something similar to rid the use of tables. <?php /************************************************************************/ /*************some variable setting**************************************/ $month = date("n"); //numeric representation of month (1-12) $year = date("Y"); //4 digit representation of year $day = date("d"); //numeric representation of the day of the month // constant variable to determine how many days alive according to the current date define('DAYS_ALIVE',(($year - 1902) * 365.24) + (($month - 1) * 30.5 )+ ($day - 1)); $divident = 100000; // variable for modulus $divider = 10000; // variable to shrink the divident for($i = 0; $i < 5; $i++) // for loop to fill the array with days alive { $daysArray[$i]= floor((DAYS_ALIVE % $divident)/$divider); //calculates the single digit to store in array $divident= $divident/10; //after every iteration the divident is decreased $divider= $divider/10; //after every iteration the divider is decreased } /*************some variable setting**************************************/ /************************************************************************/ /************PRINTING THE TABLE*****************************************/ echo '<table><tr>'; for($i=0;$i<5;++$i) { echo '<td style="vertical-align:bottom;"><table>'; for($j=0;$j<$daysArray[$i];$j++) { echo '<tr><td style="border:1px solid #000"> * </td></tr>'; } echo "<tr><td>$daysArray[$i]</td></tr></table></td>"; } echo "<tr></table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250334-help-creating-a-vertical-table-chart/#findComment-1284458 Share on other sites More sharing options...
tsuchijun Posted November 3, 2011 Author Share Posted November 3, 2011 Ahh, it was as simply as that? I was thinking maybe I had to compare the sizes of the array to determine whether or not to print a * in that cell, but thank you so much, greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/250334-help-creating-a-vertical-table-chart/#findComment-1284490 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.