7 Replies - 206 Views - Last Post: 24 January 2018 - 08:47 AM Rate Topic: -----

#1 mutago234   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 259
  • Joined: 08-September 13

Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:07 AM

I have a code below which displayed database records(hours, Minutes, Seconds) dynamically in a clock. My problem is that its only the first clock that has (hours, Minutes, Seconds) displayed. the rest of the clock shows 00:00:00 whith respect to the clock.

<?php
require('data6rst.php');

/*
create table info_timing(id int primary key auto_increment, time_hour varchar(100),time_minute varchar(100),
time_seconds varchar(100), informatia varchar(100));

insert into info_timing(time_hour,time_minute,time_seconds,informatia)values('04','30','57','My First Data');
insert into info_timing(time_hour,time_minute,time_seconds,informatia)values('06','20','01','My Second Data');
insert into info_timing(time_hour,time_minute,time_seconds,informatia)values('07','45','36','My Third Data');
*/


$data = $db->prepare("SELECT * FROM info_timing order by id desc");
		$data->execute(array());


while ($row = $data->fetch()) 
{
$id =  htmlentities($row['id'], ENT_QUOTES, "UTF-8");
$th =  htmlentities($row['time_hour'], ENT_QUOTES, "UTF-8"); 
$tm =  htmlentities($row['time_minute'], ENT_QUOTES, "UTF-8");
$ts =  htmlentities($row['time_seconds'], ENT_QUOTES, "UTF-8");
$info =  htmlentities($row['informatia'], ENT_QUOTES, "UTF-8");
//}
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <script>

function clock(){
    //calculate angle
    var d, h, m, s;
    d = new Date;

/*
h1 = 15;
h2 = 22;
h3 = 11;
*/


h1 = '<?php echo $th; ?>';
h2 = '<?php echo $tm; ?>';
h3 = '<?php echo $ts; ?>';


h = 30 * ((h1 % 12) );
    m = 6 * h2;
    s = 6 * h3;


    //move hands
    setAttr('h-hand', h);
    setAttr('m-hand', m);
    setAttr('s-hand', s);
    setAttr('s-tail', s+180);
    
    //display time

    h = h1;
    m = h2;
    s = h3;

 
    if(h >= 12){
        setText('suffix', 'PM');
    }else{
        setText('suffix', 'AM');
    }
    
    if(h != 12){
        h %= 12;
    }
    
    setText('sec', s);
    setText('min', m);
    setText('hr', h);
    
    //call every second
    setTimeout(clock, 1000);
    
};

function setAttr(id,val){
    var v = 'rotate(' + val + ', 70, 70)';
    document.getElementById(id).setAttribute('transform', v);
};

function setText(id,val){
    if(val < 10){
        val = '0' + val;
    }
    document.getElementById(id).innerHTML = val;
};

window.onload=clock;


</script>

<style>
*{
    margin:0;
    padding:0;
    font-family:sans-serif;
    font-size:14px;
}

.analog-clock{
    width:140px;
    height:140px;
}

#clock-face{
    stroke:black;
    stroke-width:2px;
    fill:white;
}

#h-hand, #m-hand, #s-hand, #s-tail{
    stroke:black;
    stroke-linecap:round;
}

#h-hand{
    stroke-width:3px;
}

#m-hand{
    stroke-width:2px;
}

#s-hand{
    stroke-width:1px;
}

.time-text{
    text-align:center;
}
</style>
        <link type="text/css" rel="stylesheet" href="style.css">
    </head>
    <body>
<b>Id:</b> <?php echo $id; ?><br>
<b>Information:</b> <?php echo $info; ?><br>
<b>Hours:</b> <?php echo $th; ?><br>
<b>Minutes:</b> <?php echo $tm; ?><br>
<b>Seconds:</b> <?php echo $ts; ?><br>

        <div class="analog-clock">
            <svg width="140" height="140">
                <circle id="clock-face" cx="70" cy="70" r="65" />
                <line id="h-hand" x1="70" y1="70" x2="70" y2="38" />
                <line id="m-hand" x1="70" y1="70" x2="70" y2="20" />
                <line id="s-hand" x1="70" y1="70" x2="70" y2="12" />
                <line id="s-tail" x1="70" y1="70" x2="70" y2="56" />
                <text x="62" y="18">12</text>
                <text x="126" y="76">3</text>
                <text x="66" y="130">6</text>
                <text x="7" y="76">9</text>
            </svg>
            <div class="time-text">
                <span id="hr">00</span>
                <span>:</span>
                <span id="min">00</span>
                <span>:</span>
                <span id="sec">00</span>
                <span id="suffix">--</span>
            </div>
        </div>
<br><br>

<?php
}
?>
    </body>
</html>



I also attach the screenshot showing the clocks

Is This A Good Question/Topic? 0
  • +

Replies To: Database Records not full displayed in a clock in php

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4212
  • View blog
  • Posts: 13,303
  • Joined: 08-June 10

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:16 AM

Anything in the error console?
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,363
  • Joined: 03-December 12

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:17 AM

What's the purpose of storing time values like that in a database?
Was This Post Helpful? 0
  • +
  • -

#4 mutago234   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 259
  • Joined: 08-September 13

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:28 AM

@#3 astonecipher because I need to generate as many clock as possible based on different rows in the database
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4212
  • View blog
  • Posts: 13,303
  • Joined: 08-June 10

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:29 AM

That's not a reason to split the time like that when you have proper date/time formats available.
Was This Post Helpful? 0
  • +
  • -

#6 mutago234   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 259
  • Joined: 08-September 13

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:36 AM

ok what could be the best approach/solution. Thanks
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4212
  • View blog
  • Posts: 13,303
  • Joined: 08-June 10

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:43 AM

save the time in a TIME field and access the parts using the HOUR(), MINUTE(), and SECOND() functions.
Was This Post Helpful? 0
  • +
  • -

#8 mutago234   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 259
  • Joined: 08-September 13

Re: Database Records not full displayed in a clock in php

Posted 24 January 2018 - 08:47 AM

ok.Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1