<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 #
 # somehow this include writes to the STDOUT
 # which screws up the generation of the gif image
 #
 #require('../sql_passwords.php');
 $z_hardcoded_password='**************';
 $z_hardcoded_database='miksup_data';
 $z_hardcoded_sqlurl='mysql1.100ws.com';
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');






 #
 # build the query to run
 #
 $query = 'SELECT count FROM `counters` where name=\'frog\' LIMIT 0, 30 ';
 #
 # run the query
 #
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #
 # loop thru and get the results of the query
 # but in this case there will only be ONE result
 #
 $zcounter_value="";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    foreach ($line as $col_value) {
        $zcounter_value=$col_value;
    }
 }
 mysql_free_result($result);
 #
 # add 1 to the counter
 # update the counter in the table
 #
 $number=$zcounter_value;
 $nextval=$zcounter_value+1;
 $query = 'update `counters` set count='.$nextval.' WHERE name=\'frog\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 // Free resultset
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);


 # 
 # now we take $number and build an image from it
 #
 # set these to the image width and height
 # after we caculate it from the digits in the image
 $xxheight=1;
 $xxwidth=0;
 #
 # read in the 10 digit images
 # may have to change this from PNG to GIF  to JPG
 #
 $ifiles[0]='0.gif';
 $ifiles[1]='1.gif';
 $ifiles[2]='2.gif';
 $ifiles[3]='3.gif';
 $ifiles[4]='4.gif';
 $ifiles[5]='5.gif';
 $ifiles[6]='6.gif';
 $ifiles[7]='7.gif';
 $ifiles[8]='8.gif';
 $ifiles[9]='9.gif';
 #
 # loop thru and open a gif file for each number from 0 to 9
 #
 for ($i=0;$i<10;$i++) {
   #list($zwidth, $zheight, $ztype, $zattr)=getimagesize($ifiles[$i]);
   $size=getimagesize($ifiles[$i]);
   $gif_width[$i]=$size[0];
   $gif_height[$i]=$size[1];
   if ($gif_height[$i] >  $xxheight ) {
     $xxheight=$gif_height[$i];
   }
   $gif[$i]=@imagecreatefromgif ($ifiles[$i]);
   if (!$gif[$i]) {
     echo "error reading file $ifiles[$i] for image $i<br>";
   }  
 }
 #
 # get the total width of the image
 # by adding up the width of each digit in the number
 #
 for ($i=0;$i<strlen($number);$i++) {
  $thisdigit=substr($number,$i,1);
  $xxwidth+=$gif_width[$thisdigit];
 }
 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);
 #
 # set the R,G,B background color of the imagee
 #
 $background_color=ImageColorAllocate($image,255,0,0);
 #
 # define RGB black as a color used on the image
 #
 $black=ImageColorAllocate($image,0,0,0);
 #
 # copy the color $black into the image between 0,0 and 50,50
 #
 #ImageFilledRectangle($image,0,0,$xxwidth,$xxheight,$black);
 #
 # convert the $number to an image
 # copy each digit of the number to our image from left to right
 #
 $next_x=0;
 for ($i=0;$i<strlen($number);$i++) {
  $thisdigit=substr($number,$i,1);
  $zfile=$ifiles[$thisdigit];
  $zhandle=$gif[$thisdigit];
  #
  # copy the gif image to our image
  #
  $rc=imagecopy ( $image, $zhandle, 
                  $next_x, ($xxheight - $gif_height[$thisdigit]) , 
                  0, 0,
                  $gif_width[$thisdigit],$xxheight);
  $rc=$rc?"true":"failed";
  $next_x=$next_x+ $gif_width[$thisdigit];
 }
 #
 # return the image
 #
 header("Content-Type: image/png");
 ImagePNG($image);
</script>  1