Page 1 of 1

Need help!!! - graph

Posted: Sun Mar 09, 2008 10:52 am
by newbie2php
Hi!

I have a database table which allows users to save their progress (of what does not matter :wink: ) over a year.

I have got this sorted and adding to the database is fine. What I am trying to do is output a basic bar chart over a course of 365 days.

I thought the easiest way was to have <DIV>s that height are controled by the value of the data in the table. But, I also need days in which no data was saved to show up as blank.

This is the code I came up with which is messy and not great, and not sure works:

(BTW - this is just the code for the bars, the rest of the graph is fine)

Code: Select all

 
$i = 0;
                        while($i < 365)
            {
                            while($bar_row = mysql_fetch_assoc($result))
                            {
                                $yesterday = mktime(0,0,0,date("m"),date("d")-$i,date("Y"));
                                if($bar_row['date'] == date("Y-m-d", $yesterday))
                                {
                                ?>
                <div style=" <?php if(date("Y-m-d") == $bar_row['date']) {echo "background-color:#0000CC";}else{echo "background-color:#FF0000";} ?>; height:<?php echo forcenumeric($bar_row['bench']); ?>px; width:2px;"></div>
                <?php
                                }
                                else
                                {
                                ?>
                <div style="background-color:#000000; height:1px; width:2px;"></div>
                <?php
                                }
                            }
                            $i ++;
            }
(as you can see - I have tried to make it so if there is data for the day we will show a red bar, else we will show a white bar which we would not be able to see. If there bar shown is todays date we make it blue)

Need help!

Can anyone offer some help/input on this?

Re: Need help!!! - graph

Posted: Sun Mar 09, 2008 12:28 pm
by newbie2php
I relised this was totally the wrong way of doing it and have now got it sorted and it looks ace.

Thanks anyway