2011-03-29 2 views
0
function estoque($data, $dias) { 
     $inicio = strtotime($data); 
     $edia = date('d', $inicio); 
     $emes = date('m', $inicio); 
     $eano = date('Y', $inicio); 
     $db = new DBConfig(); 
     $db->config(); 
     $db->conn(); 

     $data = array(); 
     while($i <= $dias) { 
      $today = strtotime(date('Y-m-d',mktime(0,0,0,date($emes),date($edia)+$i,date($eano)))); 
      //echo "<br/>".date("d-m-Y", $today)."<br/>"; 
      $query = mysql_query("SELECT * FROM quartos AS quartos 
            INNER JOIN tipos AS tipos 
            LEFT JOIN reservas AS reservas 
            ON quartos.quarto_tipo = tipos.tipo_id 
            AND quartos.quarto_numero = reservas.reserva_quarto_id 
            AND ".$today." BETWEEN reservas.reserva_checkin AND reservas.reserva_checkout 
            GROUP BY quartos.quarto_id HAVING Count(*) >= 1") or die(mysql_error()); 
      while($row = mysql_fetch_array($query)){ 
       if (empty($row["reserva_status"])) { 
        $row["reserva_status"] = "0"; 
       } 
       //echo $row["reserva_status"]."<br/>"; 
       $tmp = $i++; 
      $data[$tmp] = $row; 
      } 
      $i++; 
     } 
     $db->close(); 
     return $data; 
    } 

스마트 템플릿으로 구문 분석 할 배열을 반환하는 방법은 무엇입니까?함수에서 smarty를위한 배열을 생성하는 방법은 무엇입니까?

내 출력 템플릿 ... 내가 원하는 무엇 enter image description here

... 거의 다

enter image description here

... 내 템플릿 코드는 다음과 같습니다

     <table class="table-filtro"> 
          <thead> 
            <tr> 
             <th class="nome-quarto">Tipo</th> 
             <th>Nº Quarto</th> 
             <th>Label</th> 
             <th class="th-periodo">9</th> 
            </tr> 
          </thead> 
          <tbody> 
           {foreach from=$listar item="estoque"} 
            <tr> 
             <td class="nome-quarto">{$estoque.tipo_nome}</td> 
             <td>{if $estoque.quarto_numero|count_characters eq '1'}0{$estoque.quarto_numero}{else}{$estoque.quarto_numero}{/if}</td> 
             <td>{$estoque.quarto_descricao}</td> 
             <td><img src="http://{$smarty.server.SERVER_NAME}/reservas/images/cubos/{if $estoque.reserva_status eq '3'}vermelho{elseif $estoque.reserva_status eq '2'}amarelo{else}verde{/if}.jpg" /></td> 
            </tr> 
           {/foreach} 

          </tbody> 
         </table> 

출력 ss

enter image description here

+0

무엇을 의미합니까? 당신은 그냥 $ tpl-> assign ('estoque', estoque ($ data, $ dias);)를 수행 할 수 없습니까? – Czechnology

+0

제게 배열을 먼저 생성해야합니다. 제 기능이 배열을 생성하지 않습니다. – Hbug

답변

2

mysql_fetch_assoc()을 사용하여 배열을 반환하십시오.

function estoque($data, $dias) { 
    // ... 

    // Inside the function, already performed query... 
    $smarty_array = array(); 
    while($row = mysql_fetch_assoc($query)){ 
    // Add the current row onto $smarty_array 
    $smarty_array[] = $row; 
    } 

    // Finish up your other stuff in the function 
    // Return 
    return $smarty_array; 
} 

// Call your function 
$output_array = estoque($data, $dias); 
// Assign the array to smarty 
$smarty->assign('smartyarrayname' $output_array); 
+0

거의 거기 하지만 템플릿 레이아웃이 깨지고 있습니다 ... – Hbug

+1

데이터를 가지고 있으므로 템플릿을 수정하는 것이 다른 문제입니다. 템플릿 디스플레이와 관련된 새로운 질문을 게시하는 것이 좋습니다 –

+0

Ok, support for support :) – Hbug

관련 문제