Jump to content
Fórum Script Brasil
  • 0

Função para Inserir dados


DimitriusSantiago

Question

Boa noite.

Tenho uma tabela gerenciada por mySQL e preciso alterá-la usando PHP, é bem simples, mas não estou conseguindo. A tabela tem uma coluna para uma sequência de letras e outras colunas com a porcentagem e número absoluto de cada letra na sequência. As sequencias de letras já estão na tabela, agora preciso de um código para fazer a segunda parte, que é contar cada letra e inserir na tabela. Ex:

Seq A %A B %B C %C

AABBBCCCCC 2 20 3 30 5 50

Estou usando a seguinte função:

function contamino ($se1){
$se = mysql_query ($se1);
$se2 = mysql_result ($se, 0);
$len = strlen ($se2);
$c = 0;

while ($c < $len)
{
         $array=str_split($se2);
$char = $array[$c];
     switch ($char)
             {
                 case "a":
                 case "A": $counta++;
                     break;
                 case "r":
                 case "R": $countr++;
                     break;
                 case "d":
                 case "D": $countd++;
                     break;
                 case "n":
                 case "N": $countn++;
                     break;
                 case "c":
                 case "C": $countc++;
                     break;
                 case "e":
                 case "E": $counte++;
                     break;
                 case "q":
                 case "Q": $countq++;
                     break;
                 case "g":
                 case "G": $countg++;
                     break;
                 case "h":
                 case "H": $counth++;
                     break;
                 case "i":
                 case "I": $counti++;
                     break;
                 case "l":
                 case "L": $countl++;
                     break;
                 case "k":
                 case "K": $countk++;
                     break;
                 case "m":
                 case "M": $countm++;
                     break;
                 case "f":
                 case "F": $countf++;
                     break;
                 case "p":
                 case "P": $countp++;
                     break;
                 case "s":
                 case "S": $counts++;
                     break;
                 case "t":
                 case "T": $countt++;
                     break;
                 case "w":
                 case "W": $countw++;
                     break;
                 case "y":
                 case "Y": $county++;
                     break;
                 case "v":
                 case "V": $countv++;
                     break;
                 default:
                     break;
     }
$c++;
}

$countotal = $counta + $countr + $countd + $countn + $countc + $counte + $countq + $countg + $counth + $counti + $countl + $countk + $countm + $countf + $countp + $counts + $countt + $countw + $county + $countv;

$ResAla = $counta;
$ResArg = $countr;
$ResAsn = $countd;
$ResAsp = $countn;
$ResCys = $countc;
$ResGln = $counte;
$ResGlu = $countq;
$ResGly = $countg;
$ResIle = $counth;
$ResHis = $counti;
$ResLeu = $countl;
$ResLys = $countk;
$ResMet = $countm;
$ResPhe = $countf;
$ResPro = $countp;
$ResSer = $counts;
$ResThr = $countt;
$ResTrp = $countw;
$ResTyr = $county;
$ResVal = $countv;

$PerAla = number_format((($counta/$countotal)*100),1,',', '');
$PerArg = number_format((($countr/$countotal)*100),1,',', '');
$PerAsn = number_format((($countd/$countotal)*100),1,',', '');
$PerAsp = number_format((($countn/$countotal)*100),1,',', '');
$PerCys = number_format((($countc/$countotal)*100),1,',', '');
$PerGln = number_format((($counte/$countotal)*100),1,',', '');
$PerGlu = number_format((($countq/$countotal)*100),1,',', '');
$PerGly = number_format((($countg/$countotal)*100),1,',', '');
$PerIle = number_format((($counth/$countotal)*100),1,',', '');
$PerHis = number_format((($counti/$countotal)*100),1,',', '');
$PerLeu = number_format((($countl/$countotal)*100),1,',', '');
$PerLys = number_format((($countk/$countotal)*100),1,',', '');
$PerMet = number_format((($countm/$countotal)*100),1,',', '');
$PerPhe = number_format((($countf/$countotal)*100),1,',', '');
$PerPro = number_format((($countp/$countotal)*100),1,',', '');
$PerSer = number_format((($counts/$countotal)*100),1,',', '');
$PerThr = number_format((($countt/$countotal)*100),1,',', '');
$PerTrp = number_format((($countw/$countotal)*100),1,',', '');
$PerTyr = number_format((($county/$countotal)*100),1,',', '');
$PerVal = number_format((($countv/$countotal)*100),1,',', '');

return $PerVal;
return $PerTrp;
return $PerThr;
return $PerSer;
return $PerPro;
return $PerPhe;
return $PerMet;
return $PerLys;
return $PerLeu;
return $PerHis;
return $PerIle;
return $PerGly;
return $PerGlu;
return $PerAsp;
return $PerAsn;
return $PerAla;
return $PerArg;
return $PerCys;
return $PerGln;
}

Mas dá uma erro dizendo que não é possível dividir por 0. Alguma sugestão ?

Vlw!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...