Jump to content

Problems with populating a combobox


kroll

Recommended Posts

I have php system for reservating hotels and I have to populate a combobox that gets information from my mysql db. The person selects the event, the hotel, then they have to choose the date they will come and leave the hotel. What's happening is that my combobox only gets information from the first row from my table. Here's my code:

 

<?php 

$sql_eventos = mysql_query("SELECT * FROM fk_eventos"); 
$mt_eventos = mysql_fetch_object($sql_eventos);

list($dia_saida, $mes_saida, $ano_saida) = explode("/",$mt_eventos->fk_bloqueio_saida);
$dias = ($mt_eventos->fk_bloqueio_chegada - $mt_eventos->fk_bloqueio_saida) + 1;
?>
     <select name="saida" onChange="MM_jumpMenu('parent',this,0)" style="width:200px">
     <option value="?e=s&hotel=<?=$_REQUEST["hotel"];?>&id_evento=<?=$_REQUEST["id_evento"];?>&cidade=<?=$_REQUEST["cidade"];?>">Selecione</option>
     <?php 
 for($ds = 0; $ds < $dias; $ds++){ 

	 $d = mktime(0,0,0,$mes_saida,$dia_saida + $ds,$ano_saida);
	 $dia = date("d",$d);
	 $mes = date("m",$d);
	 $ano = date("Y",$d);
     $data_chegada =  $dia."/".$mes."/".$ano;
 ?>
      <option value="?e=s&hotel=<?=$_REQUEST["hotel"];?>&id_evento=<?=$_REQUEST["id_evento"];?>&cidade=<?=$_REQUEST["cidade"];?>&data_chegada=<?=$data_chegada;?>" <?php if($_REQUEST["data_chegada"] == $data_chegada) echo "selected"; ?>><?=$data_chegada;?></option>  
      <?php }  ?>     
     </select>
   </td>
   </tr>
         <tr>
   <td colspan="2" height="4"></td>
   <tr>

   <tr>
   <td width="22%" class="combo">Data de saída no hotel:</td>
   <td width="78%" class="combo">
  <?php
  	 $sql_eventos = mysql_query("SELECT * FROM fk_eventos"); 
 $mt_eventos = mysql_fetch_object($sql_eventos);

     if(!isset($_REQUEST["data_chegada"])){
?>
     <select name="chegada" style="width:200px" disabled>
     <option>Selecione a data de chegada</option>
     </select>
<?php }else{ ?>
     <select name="chegada" style="width:200px"  onChange="MM_jumpMenu('parent',this,0)">
     <?php 
list($dia_saida, $mes_saida, $ano_saida) = explode("/",$_REQUEST["data_chegada"]);
list($dia_chegada, $mes_chegada, $ano_chegada) = explode("/",$mt_eventos->fk_bloqueio_chegada);
$dias = ($dia_chegada - $dia_saida) + 1;

     for($ds = 0; $ds < $dias; $ds++){ 

	 $d = mktime(0,0,0,$mes_saida,$dia_saida + $ds,$ano_saida);
	 $dia = date("d",$d);
	 $mes = date("m",$d);
	 $ano = date("Y",$d);
     $data_saida =  $dia."/".$mes."/".$ano;
 ?>
      <option value="?e=s&hotel=<?=$_REQUEST["hotel"];?>&id_evento=<?=$_REQUEST["id_evento"];?>&cidade=<?=$_REQUEST["cidade"];?>&data_chegada=<?=$_REQUEST["data_chegada"];?>&data_saida=<?=$data_saida;?>&tarifas=s" <?php if($_REQUEST["data_saida"] == $data_saida) echo "selected"; ?>><?=$data_saida;?></option>  
      <?php } ?>     
     </select>
      <?php } ?>     

 

 

and my db:


CREATE TABLE `fk_eventos` (
  `fk_id_eventos` int(11) NOT NULL AUTO_INCREMENT,
  `fk_eventos` varchar(250) NOT NULL,
  `fk_id_hotel` int(11) NOT NULL,
  `fk_ano` char(4) NOT NULL,
  `fk_periodo_saida` char(10) NOT NULL,
  `fk_periodo_chegada` char(10) NOT NULL,
  `fk_bloqueio_saida` char(10) NOT NULL,
  `fk_bloqueio_chegada` char(10) NOT NULL,
  `fk_evento` varchar(150) NOT NULL,
  `fk_local` varchar(200) NOT NULL,
  `fk_endereco` varchar(200) NOT NULL,
  `fk_bairro` varchar(100) NOT NULL,
  `fk_cidade` varchar(150) NOT NULL,
  `fk_estado` varchar(10) NOT NULL,
  `fk_pais` varchar(100) NOT NULL,
  `fk_descricao` longtext NOT NULL,
  `fk_observacao` longtext NOT NULL,
  `fk_imagem` varchar(300) NOT NULL,
  `fk_destaque` char(1) NOT NULL,
  PRIMARY KEY (`fk_id_eventos`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `fk_eventos`
--

INSERT INTO `fk_eventos` VALUES(2, '1', 29, '2010', '10/06/2010', '12/06/2010', '9/06/2010', '11/06/2010', '', 'Rua Frei Caneca, 569', '', '', '1', 'SP', 'Brasil', 'O 23º COTESP 2010, nosso congresso, nascido da “Jornada do Interior” acontecerá, pela primeira vez, na capital paulista no Centro de Convenções Frei Caneca, localizado no centro da cidade.', '', '../imagens/header.jpg', '1');
INSERT INTO `fk_eventos` VALUES(3, '4', 33, '2010', '13/11/2010', '15/11/2010', '12/11/2010', '14/11/2010', '', 'Brasília', '', '', '4', 'DF', '', ' 42º Congresso Brasileiro de Ortopedia e Traumatologia - CBOT', '', '../imagens/logo_sbot.jpg', '1');
INSERT INTO `fk_eventos` VALUES(4, '3', 21, '2010', '13/05/2010', '15/05/2010', '12/05/2010', '14/05/2010', '', 'Campos do Jordão Convention Center', '', '', '3', 'SP', '', 'VIII CONGRESSO BRASILEIRO DE CIRURGIA DO OMBRO E COTOVELO. Acontecerá de 13 a 15 de maio de 2010 em Campos do Jordão - SP. http://www.cbcoc2010.com.br ', '', '../imagens/CBCOC_2010_Logo.jpg', '1');
INSERT INTO `fk_eventos` VALUES(5, '2', 30, '2010', '15/07/2010', '17/07/2010', '14/07/2010', '16/07/2010', '', 'Hotel Intercontinental', '', '', '2', 'RJ', '', 'Pela sexta vez, estaremos novamente reunidos aqui no Rio de Janeiro para discutir, aprender e trocar idéias em torno de um assunto palpitante que é a Artroplastia. ', '', '../imagens/logo.jpg', '1');

 

 

Link to comment
Share on other sites

You need to find out how many rows the query has returned and then loop through the results.

 

 

Pseudo Code


$number_of_rows = mysql_num_rows($sql_eventos)  //Get number of rows returned 

<select>

for ($count=0; $count< $number_of_rows; $count++) {
       <option value........>
}

</select>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.