2014-02-07 2 views
0

나는 다른 날 (No Table Three Column Category Layout)과 관련하여 도움을 얻은 것에 대해 후속 질문을합니다. 다음과 같이 스크립트입니다 : 내 HTML 레이아웃에 맞게 세 개의 열로 결과 링크를 나눌 필요했다결과에 따라 숫자를 변경하는 방법

$res = mysql_query($query); 
$system->check_mysql($res, $query, __LINE__, __FILE__); 
$parent_node = mysql_fetch_assoc($res); 
$id = (isset($parent_node['cat_id'])) ? $parent_node['cat_id'] : $id; 
$catalist = ''; 
if ($parent_node['left_id'] != 1) 
{ 
    $children = $catscontrol->get_children_list($parent_node['left_id'], $parent_node['right_id']); 
    $childarray = array($id); 
    foreach ($children as $k => $v) 
    { 
     $childarray[] = $v['cat_id']; 
    } 
    $catalist = '('; 
    $catalist .= implode(',', $childarray); 
    $catalist .= ')'; 
    $all_items = false; 
} 

$NOW = time(); 

/* 
specified category number 
look into table - and if we don't have such category - redirect to full list 
*/ 
$query = "SELECT * FROM " . $DBPrefix . "categories WHERE cat_id = " . $id; 
$result = mysql_query($query); 
$system->check_mysql($result, $query, __LINE__, __FILE__); 
$category = mysql_fetch_assoc($result); 

if (mysql_num_rows($result) == 0) 
{ 
    // redirect to global categories list 
    header ('location: browse.php?id=0'); 
    exit; 
} 
else 
{ 
    // Retrieve the translated category name 
    $par_id = $category['parent_id']; 
    $TPL_categories_string = ''; 
    $crumbs = $catscontrol->get_bread_crumbs($category['left_id'], $category['right_id']); 
    for ($i = 0; $i < count($crumbs); $i++) 
    { 
     if ($crumbs[$i]['cat_id'] > 0) 
     { 
      if ($i > 0) 
      { 
       $TPL_categories_string .= ' &gt; '; 
      } 
      $TPL_categories_string .= '<a href="' . $system->SETTINGS['siteurl'] . 'browse.php?id=' . $crumbs[$i]['cat_id'] . '">' . $category_names[$crumbs[$i]['cat_id']] . '</a>'; 
     } 
    } 

    // get list of subcategories of this category 
    $subcat_count = 0; 
    $query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . $id . " ORDER BY cat_name"; 
    $result = mysql_query($query); 
    $system->check_mysql($result, $query, __LINE__, __FILE__); 
    $need_to_continue = 1; 
    $cycle = 1; 
    $column = 1; 

    $TPL_main_value = ''; 
    while ($row = mysql_fetch_array($result)) 
    { 
     ++$subcat_count; 

     if ($cycle == 1) 
     { 
      $TPL_main_value .= '<div class="col'.$column.'"><ul>' . "\n"; 

     } 
     $sub_counter = $row['sub_counter']; 
     $cat_counter = $row['counter']; 
     if ($sub_counter != 0) 
     { 
      $count_string = ' (' . $sub_counter . ')'; 
     } 
     else 
     { 
      if ($cat_counter != 0) 
      { 
       $count_string = ' (' . $cat_counter . ')'; 
      } 
      else 
      { 
       $count_string = ''; 
      } 
     } 
     if ($row['cat_colour'] != '') 
     { 
      $BG = 'bgcolor=' . $row['cat_colour']; 
     } 
     else 
     { 
      $BG = ''; 
     } 

     // Retrieve the translated category name 
     $row['cat_name'] = $category_names[$row['cat_id']]; 
     $catimage = (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : ''; 
     $TPL_main_value .= "\t" . '<li>' . $catimage . '<a href="' . $system->SETTINGS['siteurl'] . 'browse.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . $count_string . '</a></li>' . "\n"; 

     ++$cycle; 
     if ($cycle == 7) // <---- here 
     { 

      $cycle = 1; 
      $TPL_main_value .= '</ul></div>' . "\n"; 
    ++$column; 
     } 
    } 

    if ($cycle >= 2 && $cycle <= 6) // <---- here minus 1 
    { 

     while ($cycle < 7) // <---- and here 
     { 
      $TPL_main_value .= ' <p>&nbsp;</p>' . "\n"; 
      ++$cycle; 


     } 
     $TPL_main_value .= '</ul></div>'.$number.' 
' . "\n"; 

    } 

. "// < ---- 여기"로 표시된 코드의 숫자를 변경하여이 작업을 수행했습니다. 반환되는 링크의 양이 매번 다를 수 있으므로 즉시 번호를 변경하는 방법을 찾으려고합니다. 나는

$number_a = mysql_num_rows($result); 
$number_b = $number_a/3; 
$number_b = ceil($number_b); 
$number_c = $number_b - 1; 

를 사용하여 다음 $number_b 또는 $number_c와 숫자를 교체하려하지만 그건 작동하지 않습니다. 어떤 아이디어?

+0

적 모듈로 들어 :

여기에 매 3 열 후 줄 바꿈을 삽입하는 데 사용하는 방법에 대한 간단한 예입니다? – Ares

+0

지금까지. 어떻게 사용할 수 있습니까? – mobilestimulus

+0

모듈로 확인하려면 http://www.php.net/manual/en/internals2.opcodes.mod.php를 확인하십시오. – Naeem

답변

1

앞서 언급했듯이 mod (%) function을 사용하면됩니다.

기본적으로 나누기 후에 나머지를 얻는 것입니다. 따라서 11 % 3이라고 말하면 2이 나옵니다. 이는 나눗셈 이후 남은 부분이기 때문입니다. 그런 다음이 값을 사용하여 숫자가 3으로 나눌 수 있는지 확인하고 나머지는 0입니다. 코드 끝에 </div>을 삽입하십시오.

$cycle = 1; 
$arr = range (1, 20); 
$len = sizeof ($arr); 

for (; $cycle <= $len; $cycle++) 
{ 
    echo "{$arr[$cycle - 1]}  "; 

    if ($cycle % 3 == 0) 
    { 
     echo "\n"; 
    } 
} 

echo "\n\n"; 
+0

감사합니다. – mobilestimulus

관련 문제