smarty 與 adodb 使用範例

//smarty
{{php}}
$i++ ;
echo $i ;
{{/php}}

//smarty
{{include file='join2/tnc_gov_join_inc.htm' }} 

//smarty
{{ if  (! $list.have_game) }}
{{/if}}

//smarty
{{ if  (! $list.have_game) }}
{{else }}
{{/if}}

//smarty 註解
{{*   *}}

 

//php
// 取得參賽項目部份名冊資料replay
 $sqlstr = " select game_id , player_id ,play_group_id ,play_item_id ,class_ename,coach_id , reference , reference2 , reference_unit ,term_num ,term_spe_id
             from game 
             where  gov_code = '$_SESSION[session_log_id]'   order by play_group_id ,class_ename , term_num,player_id " ;
 $recordSet = $CONN->Execute($sqlstr) ;
 while ($row = $recordSet->FetchRow() ) {
   $id = $row['player_id'] ;    
   $game_list[$id][] =  $row  ;
   
   //以組別做呈現
   $play_group_id = $row['play_group_id'] ;    
   $play_item_id = $row['play_item_id'] ;   
   $player_id  = $row['player_id'] ; 
   $class_ename  = $row['class_ename'] ; 
   $row['player_sex'] =  $user_list[$player_id]['player_sex'] ;
   $row['player_name'] =  $user_list[$player_id]['player_name'] ;
   
   $game_list2[$class_ename][$play_group_id][] = $row ;
   $user_list[$player_id]['have_game'] = $play_group_id ;   //已參加的組別代號
 }

//smarty    
//陣列由前向後解開    
{{foreach  key=class_key item=group_data   from=$game_list2 }}
    {{foreach  key=group_key item=group_list   from=$group_data}}
        {{php}}
        $i=0 ;
        {{/php}} 
<table class =datatable width=100%>

    <caption>組別:{{$play_group_name.name[$group_key]}}{{$class_key}}</caption>
    <tr>
        <th>序號</th>  
        <th>姓名</th>
	    <th>性別</th>
    </tr>
        <!-- 項目 -->
        {{foreach key=user_key item=user_list from=$group_list }}
	     <!-- 同項目多人 -->
         <!-- 指定狀態 -->
    <tr>
        <td>
            {{php}}
            $i++ ;
            echo $i ;
            {{/php}}   
        </td>
        <td nowrap> {{$user_list.player_name}}</td>
	    <td>{{$sex[$user_list.player_sex]}}</td>	
    </tr>

        {{/foreach }} 
    {{/foreach }} 
    </table>
    <br>

{{/foreach }}

 

//php
$sqlstr = " select play_group_level   from gov  where played ='1' group by play_group_level  order by play_group_level  ";
$recordSet = $CONN->Execute($sqlstr);
while ($row = @$recordSet->FetchRow() ) {
   $play_group_level_id  = $row['play_group_level'] ;
   $level_name[$play_group_level_id] = $row['play_group_level']  ;
} 

//smarty
<form name="form1" method="post" action="sum_level_user_list.php">
  <select name="level_id" onChange="submit();">
    {{html_options options=$level_name  selected=$level_id }}
  </select>
</form>

 

//php
 $sqlstr = " select gov.gov_code ,gov.play_group_level ,gov.gov_name , count(*) as cc from player  ,gov 
             where   player.gov_code = gov.gov_code and gov.played='1'  and gov.play_group_level= '$_GET[level_id]'
             group by gov.gov_code  
             order by gov.gov_code    " ;
             
 $recordSet = $CONN->Execute($sqlstr);
 while ($row = @$recordSet->FetchRow() ) {
    $gov_list[$row['gov_code']] = $row['gov_name']  ;
}

//smarty
{{foreach  key=key1 item=list   from=$gov_list }}  
  <tr> 
    <td>{{$gov_list[$key1]}}</td>
    <td>{{$user_array[$key1][1]}}</td>
  </tr>
{{/foreach}}

ADODB
 

$recordSet = &$conn->Execute('select * from products');
if (!$recordSet) 
        print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
        print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
        $recordSet->MoveNext();
}

GetRow($sql)

FetchRow()
返回目前記錄內容的陣列,如果是檔尾(EOF),返回 false 。注意:不要把 FetchRow 和 MoveNext() 混用。

$CONN->Execute($sqlstr) or die ( $sqlstr ) ;

 

本篇發表於 程式設計。將永久鏈結加入書籤。