This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

jcarrolo01

  • *****
  • 256 posts
Question about continue statement
« on: September 21, 2019, 06:44:27 PM »
 I have a question regarding programming using "continue" statement...

In my site i'm using zara theme, and i'm building a plugin to avoid display listings from selected categories beign displayed in latest listings... Everithing is working but i have some problems filtering the latest listings... So i came here asking for some help and hope maybe you can found a easy solution for this, and maybe you can help....

The code is  this.
Code: [Select]
​            <?php View::newInstance()->_exportVariableToView('latestItems'zara_random_items()); ?>

            <?php if( osc_count_latest_items() > 0) { ?>
              <div class="block">
                <div class="wrap">
                  <?php $c 1?>

                  <?php while( osc_has_latest_items() ) { ?>
 
 
<?php if(osc_is_this_category('skip_latest'osc_item_category_id())) { ?>
<?php continue; ?>
<?php ?>
 
                    <?php zara_draw_item($c'gallery'); ?>
                   
                    <?php $c++; ?>
                  <?php ?>

 I set in administration to display in latest listings 30 listings and that value comes in function: osc_count_latest_items() with value = 30 

I build a plugin to skip listings from selected categorie to be displayed in latest listings section...

The problem is if i have for example 4 listings in a selected category to exclude be displayed in latest listings, im entering 4 times inside the below code and the continue statement send me again for the "while":

Code: [Select]
<?php if(osc_is_this_category('skip_latest'osc_item_category_id())) { ?>
<?php continue; ?>
<?php ?>

The final result, and my issue is instead have 30 listings in latest listings i only have 26, because i enter 4 times in the loop with  "continue" statement inside...


So the question is, how can i solve this????



Best Regards
« Last Edit: September 22, 2019, 12:45:18 PM by jcarrolo01 »

*

MB Themes

Re: Question about continue statement
« Reply #1 on: September 23, 2019, 08:31:04 AM »
@jcarolo
You cannot solve your issue in that way, you must find function zara_random_items in functions.php and add condition there that oc_t_item.fk_i_category_id <> your_cats   ... so resultset you get has 30 items after filters applied.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

jcarrolo01

  • *****
  • 256 posts
Re: Question about continue statement
« Reply #2 on: September 24, 2019, 12:00:54 AM »
Thanks allot for your tip...

I analyse the function and its complex.. i will try to do something with your tip...

Anyway, one more time, thanks allot..


Best regards

*

MB Themes

Re: Question about continue statement
« Reply #3 on: September 24, 2019, 08:48:06 AM »
@jcarrolo01
Welcome
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

jcarrolo01

  • *****
  • 256 posts
Re: Question about continue statement
« Reply #4 on: September 24, 2019, 08:59:36 PM »
I think you are talking, and the solution is located in this lines inside zara_random_items function

Code: [Select]
  if( $category <> '' and $category > 0 ) {
    $subcat_list = Category::newInstance()->findSubcategories( $category );
    $subcat_id = array();
    $subcat_id[] = $category;

    foreach( $subcat_list as $s) {
      $subcat_id[] = $s['pk_i_id'];
    }

    $listCategories = implode(', ', $subcat_id);

$whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') ';
  }

so i just change to:

Code: [Select]
    $listCategories = implode(', ', $subcat_id);

$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') AND ';
$whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id <> array(Cat1,Cat2,Cat3) ';


Correct??? Or I'm completely wrong???? :) :) :)



Best Regards






*

MB Themes

Re: Question about continue statement
« Reply #5 on: September 24, 2019, 09:23:01 PM »
Something like:

Code: [Select]
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') AND ';
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id not in (1,2,3,4,5) AND ';
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Marked as best answer by frosticek on September 25, 2019, 09:30:31 AM
*

jcarrolo01

  • *****
  • 256 posts
Re: Question about continue statement
« Reply #6 on: September 24, 2019, 10:14:03 PM »
Finaly i found the solution...

In function zara_random_items

Find:
Code: [Select]
  // where
  $whe  = DB_TABLE_PREFIX.'t_item.b_active = 1 AND ';
  $whe .= DB_TABLE_PREFIX.'t_item.b_enabled = 1 AND ';
  $whe .= DB_TABLE_PREFIX.'t_item.b_spam = 0 AND ';

Change to:
Code: [Select]
  $whe  = DB_TABLE_PREFIX.'t_item.b_active = 1 AND ';
  $whe .= DB_TABLE_PREFIX.'t_item.b_enabled = 1 AND ';
  $whe .= DB_TABLE_PREFIX.'t_item.b_spam = 0 AND ';
  <b>$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (140, 421, 611, 612, 613, 614, 422, 615, 618, 619, 620, 423, 621, 617, 616, 424, 622, 623, 624, 625, 425, 626, 627, 628, 608, 629, 630, 609, 631, 632, 633, 634, 610, 635, 637, 638, 636, 639, 640, 641, 642, 426) AND ';</b>

This work as expected....


Thanks allot for your tips


Best Regards