Re: LinkArray include category permalink

8 posts by 2 authors in: Forums > CMS Builder
Last Post: June 25, 2020   (RSS)

By Tom - June 20, 2020

In response to: https://www.interactivetools.com/forum/forum-posts.php?postNum=2233849#post2233849

Hello Chris,

Finally I found the solution to show all the permalink in the same page with different table according to the post above.

However, it takes a long time to load the page.

As you said, you can show you how to load all the child records all at once (caching them at the top of your page).

Please advice how to do so.

Thank You

By gregThomas - June 22, 2020

Hey Tom,

You'll need to create a foreach loop at the top of the page that gets all of the subcategory num's into a single array then makes a call to the database to select all the num values in one go using a MySQL IN statement.

Would it be possible to post the code you've created so far that shows all the permalinks? Then I can give you more details on how to set this up.

Greg Thomas







PHP Programmer - interactivetools.com

By Tom - June 22, 2020

Hello Gerg,

Thanks for your quick response.

Here is the code.

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'joinTable' => 'homepages',
'perPage' => '16',
));
?>

<!-- listing-item-container -->
<div class="listing-item-container init-grid-items fl-wrap nocolumn-lic">
<?php foreach ($listingRecords as $listing): ?>
<?php foreach ($listing['uploads3'] as $upload): ?>
<!-- listing-item -->
<div class="listing-item">
<article class="geodir-category-listing fl-wrap">
<div class="geodir-category-img">
<a href="<?php echo $listing['_link'] ?>" class="geodir-category-img-wrap fl-wrap">
<img src="https://abcdefg.com<?php echo $upload['urlPath'] ?>" alt="<?php echo $listing['ref_no'] ?>"></a>
<div class="geodir_status_date gsd_close"><i class="fal fa-desktop"></i><?php if ($listing['hd'])
{
echo "FHD";
} elseif ($listing['hd720p']) {
echo "HD";
} elseif ($listing['vr']) {
echo "VR";
} else {
echo "SD";
}
?></div>
</div>
<?php endforeach ?>
<div class="geodir-category-content fl-wrap title-sin_item">
<div class="geodir-category-content-title fl-wrap">
<div class="geodir-category-content-title-item">
<h3 class="title-sin_map"><?php
list($homepageRecords, $homepageDetails) = getRecords(array(
'tableName' => 'homepages',
'where' => '`num` IN('.mysql_escapeCSV($listing['model:values']).')',
'allowSearch' => false,
));
?>
<?php foreach ($homepageRecords as $homepage): ?>
<a href="<?php echo $homepage['_link']; ?>"><?php echo $homepage['fullname']; ?></a>
<?php endforeach ?>
</h3>
<div class="geodir-category-location fl-wrap"><a href="<?php echo $listing['_link'] ?>" ><?php echo $listing['title_text'] ?></a></div>
</div>
</div>
<div class="geodir-category-text fl-wrap">
<div class="facilities-list fl-wrap">
<div class="facilities-list-title">Genre : </div>
<ul class="no-list-style">
<li><?php $movie_cat = array_combine($listing['movie_cat:values'], $listing['movie_cat:labels']); ?>
<?php foreach ($movie_cat as $movie_catNum => $movie_catName): ?>
<a href="listings.php?movie_cat=<?php echo $movie_catNum;?>"><?php echo $movie_catName;?>, </a>
<?php endforeach ?>
</li>
</ul>
</div>
</div>
<div class="geodir-category-text fl-wrap">
<div class="facilities-list fl-wrap">
<div class="facilities-list-title">Type : </div>
<ul class="no-list-style">
<li><?php $movie_type = array_combine($listing['movie_type:values'], $listing['movie_type:labels']); ?>
<?php foreach ($movie_type as $movie_typeNum => $movie_typeName): ?>
<a href="listings.php?movie_type=<?php echo $movie_typeNum;?>"><?php echo $movie_typeName;?>, </a>
<?php endforeach ?>
</li>
</ul>
</div>
</div>
<div class="geodir-category-text fl-wrap">
<div class="facilities-list fl-wrap">
<div class="facilities-list-title">Duration : </div>
<ul class="no-list-style">
<li><?php echo $listing['play_time'] ?></li>
</ul>
</div>
</div>
<div class="geodir-category-footer fl-wrap">
<div class="facilities-list fl-wrap">
<div class="facilities-list-title">Date Added : </div>
<ul class="no-list-style">
<li><?php echo $listing['date_added'] ?></li>
</ul>
</div>
</div>
</div>
</article>
</div>

<?php endforeach ?>
<!-- listing-item end -->

Thank you

By gregThomas - June 23, 2020

Hey Tom,

Thanks for posting your code, here is an example using your sections that should point you in the right direction:

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "init.php";

  list($listingRecords, $listingDetails) = getRecords(array(
    'tableName' => 'listings',
    'joinTable' => 'homepages',
    'perPage'   => '16',
  ));

$homePageNums    = [];
$homepageRecords = [];

//Step 1) Get all of the home page values
foreach($listingRecords as $listing) {
  if(!empty($listing['model:values'])) {
    foreach($listing['model:values'] as $modelNum) {
      if(!in_array($modelNum, $homePageNums)) {
        $homePageNums[] = $modelNum;
      }
    }
  }
}

//Step 2) Get all of the home page records that are used by the listings
if($homePageNums) {
  list($homepageRecords, $homepageDetails) = getRecords(array(
    'tableName'   => 'homepages',
    'where'       => '`num` IN('.mysql_escapeCSV($homePageNums).')',
    'allowSearch' => false,
  ));
  //Group them by the home page num to make them easy to find
  $homepageRecords = array_groupBy($homepageRecords, 'num');
}


?>
<!-- listing-item-container -->
<?php foreach ($listingRecords as $listing): ?>
  <?php foreach ($listing['model:values'] as $modelNum): ?>
    <!-- Get the linked home page record from the home page records array -->
    <?php $homepage = ($homepageRecords[$modelNum])? $homepageRecords[$modelNum] : [] ?>
    <?php if($homepage): ?>
      <a href="<?php echo $homepage['_link']; ?>"><?php echo $homepage['fullname']; ?></a>
    <?php endif; ?>
  <?php endforeach ?>
<?php endforeach ?>
<!-- listing-item end -->

So the code above collects all num values for the home pages that are used on this page, then collects the home page records and groups them by their num to make them easier to find later on.

Then, when you're cycling through all the listings, the code checks if a home page record is in the array that has that num, then displays it if it exists. 

Cheers,

Greg Thomas







PHP Programmer - interactivetools.com

By Tom - June 23, 2020 - edited: June 23, 2020

Thank You Greg and it works and the page load speed improve a lot!!!

Sorry for trouble and here is another problem about the multisearch.php

<?php
require_once "../javdata/lib/viewer_functions.php";
$options['tableName'] = 'listings';
$searchOptions = array();
$searchOptions['keywords'] = @$FORM['q'];
$searchOptions['perPage'] = "16";
$searchOptions['debugSql'] = "0";
$searchOptions['orderBy'] = "field1 DESC";

$searchTables = array();
$searchTables['homepages'] = array(
'viewerUrl' => 'model.html',
'titleField' => 'fullname',
'summaryField' => 'fullname',
'searchFields' => array('fullname'),
'field5' => 'permalink',
);

$searchTables = array();
$searchTables['listings'] = array(
'viewerUrl' => 'movie.html',
'titleField' => 'user_movie',
'summaryField' => 'title_text',
'searchFields' =>
array('user_movie','jap_user_movie','ref_no','ref_no1'),
'field1' => 'date_added',
'field2' => 'ref_no1',
'field3' => 'permalink',
);

Is it possible to display both the homepages table result and the listings table result in the same div?

I success about the second row but failed in the first row,

First row 

<!--Get the result from the homepages table-->

<?php echo $record['field5'] ?>"><?php echo  $record['_title'] ?>   

Second row

<!--Get the result from the listings table-->

<?php foreach ($searchRows as $record): ?>
<?php foreach (getUploads($options['tableName'], 'uploads', $record['num']) as $upload): ?>

<a href="/<?php echo $record['field3'] ?>"><img src="https://abcdefg.com<?php echo $upload['urlPath'] ?>"></a><?php endforeach ?><?php endforeach ?>

Thank You

By gregThomas - June 24, 2020

Hey Tom,

So the issue is that the search results are not being returned in the same set of results and you're having to call the searchMultipleTables function twice? I think the problem is that the variable searchTables is declared twice, which will remove the search options you've already set for the homepage. You need to remove it the second time it's appears:

...
  'titleField'   => 'fullname',
  'summaryField' => 'fullname',
  'searchFields' => array('fullname'),
  'field5'       => 'permalink',
);

$searchTables = array(); //REMOVE THIS LINE!
$searchTables['listings'] = array(
  'viewerUrl' => 'movie.html',
  'titleField' => 'user_movie',
...

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - June 25, 2020

Hey Tom,

I think I understand now, so you want to show the summary field for entries from the listings section and the title field for entries from the home pages section?

The results returned by the searchMultipleTables function include the table name, you can use this to work out which results came from which table and display the appropriate data like this:

<?php if($record['tablename'] == 'homepages'): ?>
  <a href="<?php echo $record['field5'] ?>"><?php echo $record['_title'] ?></a>  <!--This result was gained from the homepages table-->
<?php elseif($record['tablename'] == 'listings'): ?>
  <a href="<?php echo $record['field3'] ?>"><?php echo $record['_summary'] ?></a>  <!--This result was gained from the listings table-->
<?php endif; ?>

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com