Codingphpmedo

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  ANT_THOMAS  
 To:  ALL
41694.1 
I have this code
Code: PHP
$marking0 = strtotime('sunday') * 1000;
$marking0a = $marking0 - 96400000;
$marking0 = $marking0 + 10000000;

$marking1 = strtotime('-1 week sunday') * 1000;
$marking1a = $marking1 - 96400000;
$marking1 = $marking1 + 10000000;

$markings = "
{ xaxis: { from: $marking0, to: $marking0a }, color: \"#F3F3ED\" },
{ xaxis: { from: $marking1, to: $marking1a }, color: \"#F3F3ED\" }
" ;
I need the same thing 52 times eg
Code: 
$marking2 = strtotime('-2 week sunday') * 1000;
$marking2a = $marking2 - 96400000;
$marking2 = $marking2 + 10000000;

$marking3 = strtotime('-3 week sunday') * 1000;
$marking3a = $marking3 - 96400000;
$marking3 = $marking3 + 10000000;

......

$marking52 = strtotime('-52 week sunday') * 1000;
$marking52a = $marking52 - 96400000;
$marking52 = $marking52 + 10000000;


$markings = "
{ xaxis: { from: $marking0, to: $marking0a }, color: \"#F3F3ED\" },
{ xaxis: { from: $marking1, to: $marking1a }, color: \"#F3F3ED\" },
{ xaxis: { from: $marking2, to: $marking2a }, color: \"#F3F3ED\" },
{ xaxis: { from: $marking3, to: $marking3a }, color: \"#F3F3ED\" },
.......
{ xaxis: { from: $marking52, to: $marking52a }, color: \"#F3F3ED\" }
" ;
There must be a pretty simple way to generate 52 of those without doing it all manually?

 
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
41694.2 In reply to 41694.1 

Seems like a convoluted way to do whatever this is, but yeah, here's a simple way to generate that - all untested and may contain stupid bugs because I've got a headache, but here you go...

First build the array of weeks:

    $marking = [ strtotime('sunday') * 1000 ];
    for ( var $i = 1 ; $i <= 52 ; $i++ )
        $marking[i] = strtotime((-1*$i).' week sunday') * 1000;

Then re-map each one into the desired format (use a better function name):

    function convert_to_my_format( $CurMarking )
    {
        return "{ xaxis: { from: ".($CurMarking+10000000).", to: ".($CurMarking-96400000)." }, color: \"#F3F3ED\" }";
    }

    $markings = array_map( "convert_to_my_format" , $marking );

Finally convert that array into a comma-delimited string:

    $markings = implode( "," , $markings );
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
41694.3 In reply to 41694.2 
Thanks BP. I'll give that a go tomorrow.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
41694.4 In reply to 41694.2 
Right, we're close!

If I include the var in the 2nd line I get a 500 server error.

With it removed it outputs the 52nd and final part of the array but not the full array, I've checked by changing the 52 to another number.
 
Code: 
   for ( $i = 1 ; $i <= 52 ; $i++ )
        $marking[i] = strtotime((-1*$i).' week sunday') * 1000;

   function convert_to_markings( $CurMarking )
    {
        return "{ xaxis: { from: ".($CurMarking).", to: ".($CurMarking-96400000)." }, color: \"#F3F3ED\" }";
    }

    $markings = array_map( "convert_to_markings" , $marking );

    $markings = implode( "," , $markings );
Output from that is
 
Code: 
{ xaxis: { from: 1425168000000, to: 1425071600000 }, color: "#F3F3ED" }

Please help Peter!
0/0
 Reply   Quote More 

 From:  Chris (CHRISSS)  
 To:  ANT_THOMAS     
41694.5 In reply to 41694.4 
There's a missing $ in the for loop code. $marking[i] should be $marking[$i]

Dunno if that will fix it though.

Me
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Chris (CHRISSS)     
41694.6 In reply to 41694.5 
I have literally just spotted that, working now :D
0/0
 Reply   Quote More 

 From:  Chris (CHRISSS)  
 To:  ANT_THOMAS     
41694.7 In reply to 41694.6 
Good timing :D Glad it's working.

Me
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Chris (CHRISSS)     
41694.8 In reply to 41694.7 
It nicely highlights the weekends on my electricity usage chart.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Chris (CHRISSS)     
41694.9 In reply to 41694.5 
Bah! Damn PHP and its stupid dollars.
0/0
 Reply   Quote More 

 From:  Chris (CHRISSS)  
 To:  ANT_THOMAS     
41694.10 In reply to 41694.8 
Is that from the camera you have pointing at your electric meter?

Me
0/0
 Reply   Quote More 

 From:  Chris (CHRISSS)  
 To:  Peter (BOUGHTONP)     
41694.11 In reply to 41694.9 
Who puts dollar symbols in front of variable names? :(

Me
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Chris (CHRISSS)     
41694.12 In reply to 41694.11 
jquery. Well, in front of selectors.

----
"American football is when a bunch over over paid American sports people frightened of being hurt strap on a ton of armour to play a game of rugby"
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Chris (CHRISSS)     
41694.13 In reply to 41694.10 
That's the one.

I was originally just putting it in a spreadsheet and trawling through a load of readings every week or so (never got OCR working).

But now I've got it all in a MySQL database where I've got a little form that checks the last row in the database, then checks the date and displays the image for the next reading I need to enter, once entered it calculates the usage that day and the cost that day and adds them to the database. Data stored is - date, total meter reading, daily usage, cost. When it's up to date it tells me there's nothing more to add.

 
 

Attachments:

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ANT_THOMAS     
41694.14 In reply to 41694.13 
The last 12 Weeks

Attachments:

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Chris (CHRISSS)     
41694.15 In reply to 41694.11 
Idiots who blindly copy bits of shell script into a toy language without really knowing what they're doing, and then come up with lame justifications of why they shouldn't fix the nonsense when everyone uses the damned thing. Probably.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)     
41694.16 In reply to 41694.12 
A perfect example!

...of an idiot who doesn't know what things are. :S

Hmm, bit harsh? Maybe just a dunce. (hug)

jQuery neither prefixes variable names not puts dollars in front of selectors. It aliases itself as $, and as a function it can have arguments, the first of which can be a selector, though it also can be other things, and also has various methods attached to the function's object itself.

Which is not to say it isn't a bit dumb, but it is at least more convenient than typing case sensitive jQuery, though even that isn't as $durbrained $as $bloody $_PHP.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
41694.17 In reply to 41694.14 
It seems cost is just half of usage - or does that change?
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
41694.18 In reply to 41694.17 
Cost is calculated based on a standing daily rate + (units used * unit rate)
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
41694.19 In reply to 41694.15 
I've been wondering about that lately. Linux is, in theory, a much more secure OS than windows. But how many Linux users consist of people like me that spend days at a time running commands and scripts they find down the back of the internet trying to make bits of software work without any real clue of wtf they are actually doing? 

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  koswix     
41694.20 In reply to 41694.19 
Depending on your level of knowledge, running a command is less of an issue because you can see what you're inputting (and hopefully have some idea what it does, but often not), running scripts though is a different issue since I doubt most people check every line.

Could have a format c: in there somewhere.
0/0
 Reply   Quote More 

Reply to All  
 

1–20  21–23

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats