EchoFool Posted June 4, 2008 Share Posted June 4, 2008 I have the idea of making a hourly statistic output for a business on its sales for a 24 hour cycle. As there are 24 hours in day, would that mean I need 24 fields in a business table to do this? For example I currently have done this: -------- Business ID Owner ID Money RecordID 01:00 Sales Total 02:00 Sales Total 03:00 Sales Total (etc up to 24:00 Sales Total) -------- Is this the most efficient way to do it? It seems an awful lot of duplicated fields.. don't know if there is perhaps a smarter way to approach this? Quote Link to comment https://forums.phpfreaks.com/topic/108768-database-table-sales-chart/ Share on other sites More sharing options...
LooieENG Posted June 5, 2008 Share Posted June 5, 2008 You could use one column (wages) Say wages for hour one = 10 <?php $h = 10 // insert into db // db now contains 10 ?> then after another hour <?php $h = 20 $result = mysql_query("SELECT wages FROM table"); $row = mysql_fetch_array($result); $data = $row['wages'] . ',' . $h; // update db // db now contains 10,20 ?> And then you could explode the results at the end of 24 hours into an array <?php $result = mysql_query("SELECT wages FROM table"); $row = mysql_fetch_array($result); $wages = explode(',', $row['wages']); // $wages[0] = 10 // $wages[1] = 20 // etc.. ?> Not sure if that's practical though, there's probably a better way I don't know about P.S. Just read your post again, not sure where I got wages from, lol. Quote Link to comment https://forums.phpfreaks.com/topic/108768-database-table-sales-chart/#findComment-558018 Share on other sites More sharing options...
Daniel0 Posted June 5, 2008 Share Posted June 5, 2008 Just record the time the sale was made and sort the statistic results accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/108768-database-table-sales-chart/#findComment-558256 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.