Jump to content

Database table sales chart


EchoFool

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/108768-database-table-sales-chart/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.