Jump to content

help creating a vertical table chart


tsuchijun

Recommended Posts

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.tableqv.th.png

 

Link to comment
Share on other sites

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>";
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.