Jump to content


Photo

Listar Por Ordem Numérica


  • Faça o login para participar
1 reply to this topic

#1 Leo_cgi

Leo_cgi

    12 Horas

  • Usuários
  • 141 posts
  • Sexo:Não informado

Posted 10/10/2012, 08:30

Olá!
Estou desenvolvendo um sistema de sorteio (15 bolas sorteadas).

Abaixo segue a tabela do MySQL com os dados dos 3 sorteios:

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Banco de Dados: `banco`
--

-- --------------------------------------------------------

--
-- Estrutura da tabela `bolas`
--

CREATE TABLE IF NOT EXISTS `bolas` (
  `id` int(3) NOT NULL AUTO_INCREMENT,
  `bola1` smallint(2) NOT NULL,
  `bola2` smallint(2) NOT NULL,
  `bola3` smallint(2) NOT NULL,
  `bola4` smallint(2) NOT NULL,
  `bola5` smallint(2) NOT NULL,
  `bola6` smallint(2) NOT NULL,
  `bola7` smallint(2) NOT NULL,
  `bola8` smallint(2) NOT NULL,
  `bola9` smallint(2) NOT NULL,
  `bola10` smallint(2) NOT NULL,
  `bola11` smallint(2) NOT NULL,
  `bola12` smallint(2) NOT NULL,
  `bola13` smallint(2) NOT NULL,
  `bola14` smallint(2) NOT NULL,
  `bola15` smallint(2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Extraindo dados da tabela `bolas`
--

INSERT INTO `bolas` (`id`, `bola1`, `bola2`, `bola3`, `bola4`, `bola5`, `bola6`, `bola7`, `bola8`, `bola9`, `bola10`, `bola11`, `bola12`, `bola13`, `bola14`, `bola15`) VALUES
(1, 20, 23, 12, 8, 6, 1, 7, 11, 14, 4, 16, 10, 9, 17, 24),
(2, 16, 5, 25, 24, 23, 8, 12, 2, 17, 18, 1, 10, 4, 19, 13),
(3, 15, 13, 20, 2, 11, 24, 9, 16, 4, 23, 25, 12, 8, 19, 1),
(4, 23, 19, 1, 5, 7, 21, 16, 10, 15, 25, 6, 2, 12, 4, 17);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Abaixo segue o PHP que carrega as bolas do sorteio:
<html>
 <head>
  <title>Exibir dados com PHP/MySql</title>
 </head>
<body>

<h1>Exibir dados com PHP/MySql</h1>

<?php

$servidor = "localhost"; /*maquina a qual o banco de dados está*/
$usuario = "user"; /*usuario do banco de dados MySql*/
$senha = "senha"; /*senha do banco de dados MySql*/
$banco = "banco"; /*seleciona o banco a ser usado*/

$conexao = mysql_connect($servidor,$usuario,$senha);  /*Conecta no bando de dados MySql*/

mysql_select_db($banco); /*seleciona o banco a ser usado*/

$res = mysql_query("select * from bolas"); /*Executa o comando SQL, no caso para pegar todos os usuarios do sistema e retorna o valor da consulta em uma variavel ($res)  */

echo "<table><tr><td>Jogo</td>
<td>Bola 1</td>
<td>Bola 2</td>
<td>Bola 3</td>
<td>Bola 4</td>
<td>Bola 5</td>
<td>Bola 6</td>
<td>Bola 7</td>
<td>Bola 8</td>
<td>Bola 9</td>
<td>Bola 10</td>
<td>Bola 11</td>
<td>Bola 12</td>
<td>Bola 13</td>
<td>Bola 14</td>
<td>Bola 15</td></tr>";

/*Enquanto houver dados na tabela para serem mostrados será executado tudo que esta dentro do while */
while($escrever=mysql_fetch_array($res)){

/*Escreve cada linha da tabela*/
echo "<tr><td>" . $escrever['id'] . "</td>
<td>" . $escrever['bola1'] . "</td>
<td>" . $escrever['bola2'] . "</td>
<td>" . $escrever['bola3'] . "</td>
<td>" . $escrever['bola4'] . "</td>
<td>" . $escrever['bola5'] . "</td>
<td>" . $escrever['bola6'] . "</td>
<td>" . $escrever['bola7'] . "</td>
<td>" . $escrever['bola8'] . "</td>
<td>" . $escrever['bola9'] . "</td>
<td>" . $escrever['bola10'] . "</td>
<td>" . $escrever['bola11'] . "</td>
<td>" . $escrever['bola12'] . "</td>
<td>" . $escrever['bola13'] . "</td>
<td>" . $escrever['bola14'] . "</td>
<td>" . $escrever['bola15'] . "</td></tr>";

}/*Fim do while*/

echo "</table>"; /*fecha a tabela apos termino de impressão das linhas*/

mysql_close($conexao);

?>

</body>
</html>

Agora eu queria uma ajuda de vocês para conseguir listar as bolas do sorteio em ordem numérica.

Poderiam me ajudar?

Valeu!

#2 shayllis

shayllis

    12 Horas

  • Usuários
  • 152 posts
  • Sexo:Masculino
  • Localidade:Barueri - SP
  • Interesses:PHP, MySQL, ASP.NET C# e VB, DreamWeaver, VisualStudio, JavaScript

Posted 22/10/2012, 15:06

Order by campo

Simples assim


mas seu código está estranho viu... Tenta faze algo mais enxuto, usando foreach e for, não precisa ir linha por linha dando echo.




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq