Jump to content

Time Stamp


unknown87

Recommended Posts

<?php require_once("includes/connection.php"); ?>
<?php


$query = 'SELECT runs FROM runs';

$result = mysql_query($query);


while ($row = mysql_fetch_assoc($result)) {
    
    $scores[] = $row['runs'];    
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Cricket Stats</title>
    <script type="text/javascript">
    
        var scores = new Array();
        
    <?php
               
        foreach ($scores as $score) {
            
            
            static $i = 0;
            
            $scored = "scores[$i] = $score;\n";

		echo $scored;

           
            $i++; 	
        }
    ?>


    
        function updateScore(count)
        {
         
            if (!count) var count = 1;
            
            var container;
            
            
            if (!(container = document.getElementById("score_counter"))) return false;
            
             the same index as 'count'
            container.innerHTML = scores[count];
            
            
            count++;
            
            
            setTimeout('updateScore('+count+')', 500);
        }
    
    </script>
</head>

<body onload="updateScore()">

    <div id="score_counter"></div>

</body>
</html>

<?php

mysql_close($connection);
?>

 

1) I can't get the code to recognise letters because in the database there is a few times where its got the word "OUT".  When it gets to the word "OUT", it dies and does not finish.

 

2) Also the numbers appear and then disappear and then the next number is displayed.  I don't want the any numbers to disappear instead, i need them to be listed for example:

 

number 1

 

30 seconds later

 

number 1

number 2

 

... and so on.

 

This is what i tried but with no luck.

<?php require_once("includes/connection.php"); ?>
<?php


$query = 'SELECT runs FROM runs';

$result = mysql_query($query);


while ($row = mysql_fetch_assoc($result)) {
    
    $scores[] = $row['runs'];    
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Cricket Stats</title>
    <script type="text/javascript">
    
        var scores = new Array();
        
    <?php
             
        foreach ($scores as $score) {
            
         
            static $i = 0;
            
            $scored = "scores[$i] = $score;\n";

		echo $scored;

		$query = "INSERT INTO played (runs) VALUES ('$score')";
$result = mysql_query($query, $connection);
if (!$result) {
	die("Database query failed: " . mysql_error());
}

            
            $i++; 	
        }
    ?>

<?php

$result = mysql_query("SELECT * FROM played", $connection);
if (!$result) {
	die("Database query failed: " . mysql_error());
}


while ($row = mysql_fetch_array($result)) {
	echo $row["runs"]."<br />";
}

?>

    
        function updateScore(count)
        {
            
            if (!count) var count = 1;
            
            var container;
            
            
            if (!(container = document.getElementById("score_counter"))) return false;
            
           
            container.innerHTML = scores[count];
            
           
            count++;
            
           
            setTimeout('updateScore('+count+')', 500);
        }
    
    </script>
</head>

<body onload="updateScore()">

    <div id="score_counter"></div>

</body>
</html>

<?php

mysql_close($connection);
?>

 

Can anyone help me this.

 

Thanks in advance

Link to comment
Share on other sites

<?php
              
        foreach ($scores as $score) {
            
            
            static $i = 0;
            
           
            echo "scores[$i] = '" . str_replace("'", "\'", $score) . "';\n";
            
            
            $i++;            
        }
    ?>

 

Thats number 1 sorted.

 

Still need help with number 2

 

Link to comment
Share on other sites

www.php.net/sleep

 

You can use the sleep function to do the following.  I am not sure what the timeout is but it will eventually time out. The best bet is to use AJAX as someone suggested before and just have javascript keep track of the timer.

 

<?php
              
        foreach ($scores as $score) {
            
            
            static $i = 0;
            
           
            echo "scores[$i] = '" . str_replace("'", "\'", $score) . "';\n";
            sleep(30);
            
            $i++;            
        }
    ?>

Link to comment
Share on other sites

<?php require_once("includes/connection.php");

$i = 0;

while ($i < 299) {                                                                
    
    $batsmen = rand(1,100);
    
    if ($batsmen <= 40) {
        $scores[] = 0;                                                            
    } else if ($batsmen <= 60) {
        $scores[] = 1;
    } else if ($batsmen <= 70) {
        $scores[] = 2;
    } else if ($batsmen <= 75) {
        $scores[] = 3;
    } else if ($batsmen <= 90) {
        $scores[] = 4;
    } else if ($batsmen <= 95) {
        $scores[] = 6;
    } else {
        $scores[] = "out";
    }
    
    $i++;
} 

$query = "INSERT INTO runs (runs) VALUES ('" . implode("' , '", $scores) . "')"; 

    
$result = mysql_query($query, $connection);

if (!$result) {
die("Database query failed: " . mysql_error());
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Cricket Stats</title>
    <script type="text/javascript">

<?php    
        foreach ($scores as $score) {
            
            static $i = 0;
            
            echo "scores[$i] = '" . str_replace("'", "\'", $score) . "';\n";
            
            $i++;            
        }
    ?>
	function updateScore(count, outs)
        {
            if (!count) var count = 0;            
            if (!outs) var outs = 0;
            
            var container;
            
            if (!(container = document.getElementById("score_counter"))) return false;
            
            var current_score = scores[count];

            if (current_score.match(/out/i)) outs++;
            
            container.innerHTML += current_score + unescape("%3Cbr%3E");
            
            count++;
            
            if (outs > 9 || count > 300) {
                
                return false;                
            }

            setTimeout('updateScore('+count+','+outs+')', 2000);
        }
    </script>
</head>

<body onload="updateScore()">

    <div id="score_counter"></div>

</body>
</html>

<?php
mysql_close($connection);
?>

 

Can anyone help me with this error:

 

Database query failed: Column count doesn't match value count at row 1

 

thanks in advance

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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