#!/usr/bin/perl -w

use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:all/;
use DBI;

my $squery="select med from tbl_artothtree where val='0.00000' or val='000000' group by 1 order by 1";
my $dbh=DBI->connect('dbi:mysql:arabdemog_com:arabiandemographics.com','arabdemog_com','p2a9r7cd') || die('cannot conect to database');
#my $dbh=DBI->connect('dbi:mysql:arabdemog_com:parcsys','arabdemog_com','') || die('cannot conect to database');

my $sthE=$dbh->prepare($squery) || $dbh->errstr;
my $rv=$sthE->execute  || $sthE->errstr;
foo: while (@row=$sthE->fetchrow_array())
{
  $sql="select med,max(val),spc from tbl_artothtree where med ='$row[0]' group by 1";
	my $sthE1=$dbh->prepare($sql) || $dbh->errstr;
	my $rv=$sthE1->execute  || $sthE->errstr;
	foo1: while (@row1=$sthE1->fetchrow_array())
	{
		$sql1="update tbl_artothtree set val=$row1[1]/$row1[2]*spc where med='$row1[0]' and (val='0.00000' or val='000000') ";
		$sthE2=$dbh->prepare($sql1) || $dbh->errstr;
		$rv=$sthE2->execute  || $sthE->errstr;
	#	print "$sql1\n";
	}
}
