Перейти к публикации
View in the app

A better way to browse. Learn more.

Дизайн и модификация Invision Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Базы данных со сложной структурой

Опубликовано:

Задача такова - нужно вывести в родительской категории все статьи из подкатегорий, желательно, рассортированные по подкатегориям.

 

База данных - своя.

Буду рада, если кто-то предложит лучший вариант решения.

 

Правим файл /admin/applications_addon/ips/ccs/sources/databases.php

Строка 590:

Было:

$_where		= $_where ? "category_id=" . intval($this->request['category']) . " AND (" . $_where . ")" : "category_id=" . intval($this->request['category']);

 

Стало:

             if(is_array($categories))
              {
        	$cats=array_keys($categories);
              }

$cats[]=intval($this->request['category']);
$_where	= $_where ? "category_id=" . intval($this->request['category']) . " AND (" . $_where . ")" : 'category_id="' . implode('" OR category_id="', $cats).'"';

 

Это позволит отображать все статьи подкатегорий в родительской категории. Почему OR, а не IN - насколько я помню, он в целом исполняется быстрее.

 

 

Дальше, шаблон списка категорий(Database Listing):

{ccs special_tag="navigation"}
<if test="is_array($data['categories']) AND count($data['categories'])">
{parse striping="generic_cats" classes="row1,row2"}
<div class='category_block block_wrap clear'>
   <h3 class='maintitle'>{$data['parent']['category_name']}</h3>
   <table width='100%' class='ipb_table'>
		<foreach loop="$data['categories'] as $category">
              <tr class='{parse striping="generic_list"}'>
              		<td style='width: 5%;'>
              			{parse replacement="{$category['image']}"}
              		</td>
				<td style='width: 85%;'>
					<strong><a href='{$category['category_link']}'>{$category['category_name']}</a></strong>
					<if test="$category['category_description']"><p class='desc'>{$category['category_description']}</p></if>
					<if test="count($category['children'])">
						<h5 class='hide'>{$this->lang->words['ccs_subcats']}</h5>
						<ol class='subforums'>
						<foreach loop="$category['children'] as $_data">
<li<if test="$_data['_has_unread']"> class='newposts'</if>><a href='{$_data['category_link']}'>{$_data['category_name']}</a></li>
						</foreach>
						</ol>
					</if>
				</td>
              </tr>
		</foreach>
   </table>
</div>
</if>

<if test="$data['show']">	
<div class='category_block block_wrap clear'>
	<table width='100%' class='ipb_table'>
		<if test="count($data['records'])">
<foreach loop="$data['categories'] as $category">
<tr><td>
<h3>{$category['category_name']}</h3>
</td></tr>
		<foreach loop="$data['records'] as $record">
<if test="$category['category_id']==$record['category_id']">
				<php>$this->didLink	= false;</php>
				<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
			        <td><a href="{$record['record_link']}">{$record['field_19_value']} ({$record['category_id']})</a></td>
				</tr>
</if>
			</foreach>
</foreach>
		<else />
			<tr>
				<td colspan="<if test="$fieldCount = count($data['fields']) + 1">{$fieldCount}</if>">
{$this->lang->words['no_records_found']}</td>
			</tr>
		</if>
	</table>
</div>
</if>

 

Вроде всё работает, но мне не нравится двойной цикл. Может кто-то что-то может предложить?

Рекомендованные сообщения

Опубликовано:
  • Автор

Я осознала свою ошибку. Вот обновлённый шаблон.

 

{ccs special_tag="navigation"}
<if test="$data['show']">	
<div class='category_block block_wrap clear'>
	<table width='100%' class='ipb_table'>
<if test="is_array($data['categories']) AND count($data['categories'])">
<foreach loop="$data['categories'] as $category">
<tr><td>
<h3><a href='{$category['category_link']}'>{$category['category_name']}</a></h3>
</td></tr>
<if test="count($data['records'])">
<foreach loop="$data['records'] as $record">
<if test="$category['category_id']==$record['category_id']">
<php>$this->didLink	= false;</php>
<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
<td><a href="{$record['record_link']}">{$record['field_19_value']}</a></td>
</tr>
</if>
</foreach>
</if>
</foreach>
<else />
<h3><a href='{$data['parent']['category_link']}'>{$data['parent']['category_name']}</a></h3>
<if test="count($data['records'])">
<foreach loop="$data['records'] as $record">
<php>$this->didLink	= false;</php>
<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
<td><a href="{$record['record_link']}">{$record['field_19_value']}</a></td>
</tr>
</foreach>
</if>

</if>
</table>
</if>

Создайте аккаунт или войдите в него для комментирования

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.