Carlos Rocha Posted July 24, 2014 at 07:20 PM Report Share #563304 Posted July 24, 2014 at 07:20 PM (edited) Pessoal, boa tarde, preciso de uma ajuda para montar o nome da variavel. Seguinte: Minha tabela tem 12 campos datapg que variam de datapg1 à datapg12. Mas na hora de validar, só poderei validar alguns deles então fiz assim: $contaI sempre tem valor diferente e maior que 1. $contaI = floor($dataConta/30); $nome = "datapg"; for ($i=1; $i<=$contaI; $i++) { if ( ("datapg".$i != "0000-00-00") && ("datapg".$i != "") && ("datapg".$i != NULL) ) { $contador++; } } Como faço para formar o nome da variável dataprog + 1? Edited July 24, 2014 at 07:49 PM by carcleo Link to comment Share on other sites More sharing options...
Devexz Posted July 24, 2014 at 08:06 PM Report Share #563306 Posted July 24, 2014 at 08:06 PM epa, estou com bué preguiça de explicar por isso deixo alguns links e conceitos: http://php.net/manual/en/language.variables.variable.php http://stackoverflow.com/questions/9257505/dynamic-variable-names-in-php ( este acho que tem um problema parecido ao teu ). http://foundationphp.com/blog/2010/12/18/understanding-php-variable-variables/ Contador de calorias: caloriaspordia.com Link to comment Share on other sites More sharing options...
Carlos Rocha Posted July 24, 2014 at 09:17 PM Author Report Share #563318 Posted July 24, 2014 at 09:17 PM Deu certo assim: $contador = 0; $dataConta = strtotime(date("Y-m-d")) - strtotime($dataInicio); $dataConta = $dataConta/86400; if ($dataConta >= 366 ) {$dataConta = $dataConta - 366;} $contaI = ceil($dataConta/30); $nome = "datapg"; for ($i=1; $i<$contaI+1; $i++) { if ( (${$nome.$i}== "0000-00-00") || (${$nome.$i} == "") || (${$nome.$i} == NULL) ) { $contador++; } } $alunosListados++; if ($contador==0) { //$alunosQuites[$alunosListados]=$idfrequencia; array_push($alunosQuites,$idfrequencia); } else { //$alunosDebito[$alunosListados]=$idfrequencia; array_push($alunosDebito,$idfrequencia); } Obrigado! Link to comment Share on other sites More sharing options...
charly Posted August 29, 2014 at 02:17 PM Report Share #565692 Posted August 29, 2014 at 02:17 PM Poderiam sempre utilizar a solução de um array. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now