2014-04-17 3 views
0

$za_play 변수를이 스크립트의 제품 clip_filename에 설정하려고합니다. 배열별로 여러 클립을 얻는 데 혼란스러워서 제품 당 클립이 하나뿐입니다. clip filename에 $za_play을 어떻게 설정합니까?PHP가 배열에서 변수를 설정했습니다.

<?php 
/** 
* iterates thru media collections/clips 
* 
* @package productTypes 
* @copyright Copyright 2003-2009 Zen Cart Development Team 
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 
* @version $Id: media_manager.php 11825 2009-01-15 09:46:19Z drbyte $ 
*/ 
if (!defined('IS_ADMIN_FLAG')) { 
    die('Illegal Access'); 
} 

/** 
* get list of media collections assigned to specified product 
*/ 
$zv_collection_query = "select media_id, product_id from " . TABLE_MEDIA_TO_PRODUCTS . " 
         where product_id = '" . (int)$_GET['products_id'] . "'"; 
$zq_collections = $db->Execute($zv_collection_query); 
$zv_product_has_media = false; 
**$za_play = 'HELLO';** 
/** 
* loop thru collections to identify actual media clips 
*/ 
if ($zq_collections->RecordCount() > 0) { 
    $zv_product_has_media = true; 
    while (!$zq_collections->EOF) { 
    /** 
    * get names of assigned media collections 
    */ 
    $zf_media_manager_query = "select media_id, media_name from " . TABLE_MEDIA_MANAGER . " 
           where media_id = '" . (int)$zq_collections->fields['media_id'] . "'"; 
    $zq_media_manager = $db->Execute($zf_media_manager_query); 
    if ($zq_media_manager->RecordCount() < 1) { 
     $zv_product_has_media = false; 
    } else { 
     /** 
     * build array of [collection_id][text] = collection-name 
     */ 
     $za_media_manager[$zq_media_manager->fields['media_id']] = array('text' => $zq_media_manager->fields['media_name']); 
     /** 
     * get list of media clips associated with the current media collection, sorted by filename (to allow display sort order to be controlled by filename) 
     */ 
     $zv_clips_query = "select media_id, clip_id, clip_filename, clip_type from " . TABLE_MEDIA_CLIPS . " 
         where media_id = '" . (int)$zq_media_manager->fields['media_id'] . "' order by clip_filename"; 
     $zq_clips = $db->Execute($zv_clips_query); 
     if ($zq_clips->RecordCount() < 1) { 
     $zv_product_has_media = false; 
     } else { 
     while (!$zq_clips->EOF) { 
      /** 
      * get list of media types and filenames associated with the current media 
      * @TODO - run this as separate static array, since only needs to run once, not repeatedly in a loop 
      */ 
      $zf_clip_type_query = "select type_ext, type_name from " . TABLE_MEDIA_TYPES . " 
           where type_id = '" . (int)$zq_clips->fields['clip_type'] . "'"; 

      $zq_clip_type = $db->Execute($zf_clip_type_query); 

      $za_media_manager[$zq_media_manager->fields['media_id']]['clips'][$zq_clips->fields['clip_id']] = 
       array('clip_filename' => $zq_clips->fields['clip_filename'], 
         'clip_type' => $zq_clip_type->fields['type_name']); 
      $zq_clips->MoveNext(); 

     } 
     } 
    } 
    $zq_collections->MoveNext(); 
    } 
} 
$zv_product_has_media = (sizeof($za_media_manager)) > 0 ? TRUE : FALSE; 

**$za_play = $zq_clips->fields['clip_filename'];** 
+1

쿼리가 여러 항목을 반환하지 않는 경우 왜 결과를 처리하기 위해 'while'루프를 사용합니까? – Barmar

+0

단일 결과를 반환하는 방법을 변경하는 방법을 모르겠습니다. while 루프를 제거하지 않고 첫 번째 clip_filename 결과를 $ za_play로 가져올 수 있습니까? – user3525661

+0

'while'루프를 제거하기 만하면됩니다. 쿼리가 1 행만 반환하면 루프는 한 번만 실행됩니다. 다시 시도하면 'EOF'가 true가됩니다. – Barmar

답변

0
이 그냥 $za_play 설정

$zv_product_has_media, 그것은 원래의 코드가 생성하는 모든 다른 배열을 만드는 귀찮게하지 않습니다.

$zv_collection_query = "select media_id, product_id from " . TABLE_MEDIA_TO_PRODUCTS . " 
         where product_id = '" . (int)$_GET['products_id'] . "'"; 
$zq_collections = $db->Execute($zv_collection_query); 
$zv_product_has_media = false; 
$za_play = 'HELLO'; 
/** 
* loop thru collections to identify actual media clips 
*/ 
if ($zq_collections->RecordCount() > 0) { 
    $zv_product_has_media = true; 
    /** 
    * get names of assigned media collections 
    */ 
    $zf_media_manager_query = "select media_id, media_name from " . TABLE_MEDIA_MANAGER . " 
           where media_id = '" . (int)$zq_collections->fields['media_id'] . "'"; 
    $zq_media_manager = $db->Execute($zf_media_manager_query); 
    if ($zq_media_manager->RecordCount() < 1) { 
     $zv_product_has_media = false; 
    } else { 
     $zv_clips_query = "select media_id, clip_id, clip_filename, clip_type from " . TABLE_MEDIA_CLIPS . " 
         where media_id = '" . (int)$zq_media_manager->fields['media_id'] . "' order by clip_filename"; 
     $zq_clips = $db->Execute($zv_clips_query); 
     if ($zq_clips->RecordCount() < 1) { 
      $zv_product_has_media = false; 
     } else { 
      $za_play = $zq_clips->fields['clip_filename']; 
     } 
    } 
} 
+0

고마워요. 하지만 다른 스크립트에서 $ za_play를 호출하면 여전히 HELLO로 반환됩니까? – user3525661

+0

이 코드는 함수에 있습니까? 그렇다면 함수의 값을 반환하거나'global $ za_play '를 선언해야합니다. – Barmar

+0

'$ zv_product_has_media'의 값은 무엇입니까? 어쩌면 쿼리 중 하나가 아무것도 찾지 못할 수도 있습니다. – Barmar