Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Vinicius Araújo

Primeiro Programa

Recommended Posts

Olá Pessoal,



Bom, sou novo no fórum, e novato na área de programação, e gostaria de uma ajudinha de vocês, realizei este pequeno programa em HTML/PHP que valores são digitados e depois de clicar no botão, gera um arquivo em excel com um valor aleatório. Gostaria de saber quais melhorias eu poderia estar acrescentando nesse código.


Segue o código:




<?php

ini_set('display_errors', 0 );

error_reporting(0);

$valores = (!empty($_POST['valores'])) ? $_POST['valores'] : '';

$qtde = $_POST['quantidade'];

?>


<!DOCTYPE html>

<html>

<head>

<link href="css/bootstrap.min.css" rel="stylesheet">

<link href="css/style.css" rel="stylesheet">

<meta charset = "UTF-8">


<style>

body {

background: gray;

}

.form-control {

margin: 10px auto;

}

</style>

</head>

<body>


<script src="js/jquery.js"></script>

<script src="js/bootstrap.min.js"></script>


<form method = "post" action = "ramdom.php" class = "form-inline">


<table border = "1" align = "center" width="940" class="table-bordered">

<tr>

<td align = "center"><label><font color = "white">Valores:</font></label><br>

<textarea name = "valores" width="100" rows="10" cols = "100" class = "form-control"><?php echo $valores?></textarea></td>

</tr>

<tr>

<td align = "center">

<label><font color = "white">Quantidade:</font></label>

<input type="text" name = "quantidade" maxlength ="3" size="3" value = "<?php echo $qtde ?>" class = "form-control">

<input type="submit" name = "btngerar" value="Gerar" class = "btn btn-default">

</td>

</tr>

</table>

</form>

<br>


<div align = "center">

<?php

if (isset($_POST['btngerar'])){

$html = '';

if (empty($qtde) or empty($valores)){

$status = "<font color=\"red\"><strong>ERRO: </strong>Digite os valores e quantos valores você deseja sortear.</font>";

echo $status;

}else{

$notes = explode("\n", $_POST['valores']);

$rand_keys = array_rand($notes, $qtde);

$numlinhas = count($notes);

if ($qtde > $numlinhas ){

$status = "<font color=\"red\"><strong>ERRO:</strong>Valor da quantidade maior que total de opções.</font>";

echo $status;

}else{

echo "

<table border = 1>

<tr>

<td>Resultado:</td>

</tr>

";

if ($qtde == 1) {

$rand_keys = array_rand($notes,1);

$status = $notes[$rand_keys];

$html .= '<table>';

$html .= '<tr>';

$html .= '<td colspan="3">Resultado</td>';

$html .= '</tr>';

$html .= '<tr>';


echo "<tr>

<td>1</td><td>" . $status . "</td>

</tr>";

}else{

$n = 1;

for ($i = 0; $i < $qtde; $i++) {

$status = $notes[$rand_keys[$i]];

echo"

<tr>

<td>" . $n . " </td><td> " . $status . "</td>

</tr>";

$n++;


}

}

$html .= '</tr>';

$html .= '</table>';

$arquivo = 'Valores_Randomicos.xls';


header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");

header ("Cache-Control: no-cache, must-revalidate");

header ("Pragma: no-cache");

header ("Content-type: application/x-msexcel");

header ("Content-Disposition: attachment; filename=\"{$arquivo}\"" );

header ("Content-Description: PHP Generated Data" );


echo $html;

exit;


echo "</table>";

echo "</form>";

}

}

echo var_dump($string);

}


?>

</label>

</div>


</form>


</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.