Website Membership user type / user levels / user permissions and display of data

15 posts by 2 authors in: Forums > CMS Builder
Last Post: November 19, 2014   (RSS)

By Mikey - November 7, 2014 - edited: November 7, 2014

I'm using website membership which has a field called "membership_user_type" as radio buttons which are "Public, Prospect, Customer and Dealer".

I'm trying to display data posted to a multi section for videos which has radio buttons for "Public, Prospect, Customer and Dealer". So when a video is uploaded the CMS admin selects one of the radio buttons that the video should be associated with and who can see the video - based on their account. Below is my video load list data.

    // load records
  list($video_galleryDealerRecords, $video_galleryDealerMetaData) = getRecords(array(
    'where'      => "`membership_access` = 'Dealer' OR 'Customer' OR 'Prospect' OR 'Public'",
    //'where'      => "`membership_access` = 'Dealer'",
    //'where' => "createdByUserNum IN (SELECT num FROM cms_members WHERE membership_access LIKE 'Dealer')",
    'tableName'   => 'video_gallery',
    'perPage'     => '6',
  ));

    // load records  
  list($video_galleryCustomerRecords, $video_galleryCustomerMetaData) = getRecords(array(    
    'where'      => "`membership_access` = 'Customer' OR 'Public'",
    //'where'      => "`membership_access` = 'Customer'",    
    //'where' => "createdByUserNum IN (SELECT num FROM cms_members WHERE membership_access LIKE 'Customer')",    
    'tableName'   => 'video_gallery',    
    'perPage'     => '6',  
  ));

What I need to achieve is to display data based on multiple possible options.

For example:
Public videos would not require an account.
a Prospect would be able to view videos posted for Public and Prospect
a Customer would be able to view videos for Public and Customer
a Dealer would be able to view videos for Public, Prospect, Customer and Dealer.

But the code above doesn't seem to work... anyone have any insight on how to make this work?


Below is the code I'm using on my page to display the information based on the fact that the user is a Dealer. Yet the Dealer needs to see videos uploaded for Public, Prospect, Customer and Dealer:

<?php if($CURRENT_USER['membership_user_type'] == 'Dealer'): ?><!-- /membership_access -->
<?php foreach ($video_galleryDealerRecords as $record): ?> 
<iframe width="300" height="240" src="http://www.youtube.com/embed/<?php echo $record['youtube_video'] ?>?wmode=transparent&amp;rel=0" frameborder="0" allowfullscreen></iframe>

<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo maxWords($record['summary'], 80); ?>
<?php echo $record['num'] ?>

<?php  // maximum tags displayed if not paid advertising 
$maximumResults = 6;
$resultCount = 0;
?>
    
<?php $tagArray = array_combine( $record['video_category:values'] , $record['video_category:labels']); ?>
<?php foreach($tagArray as $value => $label): ?>
  <a href="video-gallery.php?video_category=<?php echo htmlspecialchars($value); ?>"><?php echo htmlspecialchars($label); ?></a>
<?php if (++$resultCount == $maximumResults) { break;} //maximum tags displayed ?>
<?php endforeach; ?>

<?php $tagKeywords = getListLabels('gallery', 'keywords', $record['keywords']) ?>
<?php foreach($record['keywords:values'] as $tagKeyword): ?>
<a href="video-gallery.php?keywords=<?php echo htmlspecialchars($tagKeyword) ?>"><?php echo htmlspecialchars($tagKeyword) ?></a>
<?php if (++$resultCount == $maximumResults) { break;} //maximum tags displayed ?>
<?php endforeach ?>
<?php endforeach ?>
    
<?php if (!$video_galleryDealerRecords): ?>
    <h3>No videos</h3>
    <?php endif ?>
    
<?php  
if (@!$_GET['page']): $current_page = "1"; 
else: $current_page = $_GET['page'];    
endif;  ?> 

<?php 
$startNumber = max($current_page - 8, 1); 
$endNumber   = min($current_page + 8, $video_galleryDealerMetaData['totalPages']); 
?>

<?php if ($video_galleryDealerMetaData['prevPage']): ?>
<a href="<?php echo $video_galleryDealerMetaData['prevPageLink'] ?>">Previous</a>
<?php if ($startNumber > '1'): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => '1' ))) ?> ">1</a>
<?php endif ?> 
<?php else: ?>
<?php endif ?>

<?php foreach (range($startNumber,$endNumber) as $page): ?>

<?php if ($page == $current_page): ?> 
<?php echo $page; ?>
<?php else: ?> 
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>
<?php endif ?> 

<?php endforeach; ?> 

<?php if ($video_galleryDealerMetaData['nextPage']): ?>
<?php if ($video_galleryDealerMetaData['totalPages'] > $endNumber): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $video_galleryDealerMetaData['totalPages'] ))) ?> "><?php echo $video_galleryDealerMetaData['totalPages'];?></a>
<?php endif ?> 
<a href="<?php echo $video_galleryDealerMetaData['nextPageLink'] ?>">Next</a>
<?php else: ?>
<?php endif ?>
<!-- /membership_access --><?php endif ?>






<?php if($CURRENT_USER['membership_user_type'] == 'Customer'): ?><!-- /membership_access -->
<?php foreach ($video_galleryCustomerRecords as $record): ?> 
<iframe width="300" height="240" src="http://www.youtube.com/embed/<?php echo $record['youtube_video'] ?>?wmode=transparent&amp;rel=0" frameborder="0" allowfullscreen></iframe>

<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo maxWords($record['summary'], 80); ?>
<?php echo $record['num'] ?>

<?php  // maximum tags displayed if not paid advertising 
$maximumResults = 6;
$resultCount = 0;
?>
    
<?php $tagArray = array_combine( $record['video_category:values'] , $record['video_category:labels']); ?>
<?php foreach($tagArray as $value => $label): ?>
  <a href="video-gallery.php?video_category=<?php echo htmlspecialchars($value); ?>"><?php echo htmlspecialchars($label); ?></a>
<?php if (++$resultCount == $maximumResults) { break;} //maximum tags displayed ?>
<?php endforeach; ?>

<?php $tagKeywords = getListLabels('gallery', 'keywords', $record['keywords']) ?>
<?php foreach($record['keywords:values'] as $tagKeyword): ?>
<a href="video-gallery.php?keywords=<?php echo htmlspecialchars($tagKeyword) ?>"><?php echo htmlspecialchars($tagKeyword) ?></a>
<?php if (++$resultCount == $maximumResults) { break;} //maximum tags displayed ?>
<?php endforeach ?>
<?php endforeach ?>
    
<?php if (!$video_galleryCustomerRecords): ?>
    <h3>No videos</h3>
    <?php endif ?>
    
<?php  
if (@!$_GET['page']): $current_page = "1"; 
else: $current_page = $_GET['page'];    
endif;  ?> 

<?php 
$startNumber = max($current_page - 8, 1); 
$endNumber   = min($current_page + 8, $video_galleryCustomerMetaData['totalPages']); 
?>

<?php if ($video_galleryCustomerMetaData['prevPage']): ?>
<a href="<?php echo $video_galleryCustomerMetaData['prevPageLink'] ?>">Previous</a>
<?php if ($startNumber > '1'): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => '1' ))) ?> ">1</a>
<?php endif ?> 
<?php else: ?>
<?php endif ?>

<?php foreach (range($startNumber,$endNumber) as $page): ?>

<?php if ($page == $current_page): ?> 
<?php echo $page; ?>
<?php else: ?> 
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>
<?php endif ?> 

<?php endforeach; ?> 

<?php if ($video_galleryCustomerMetaData['nextPage']): ?>
<?php if ($video_galleryCustomerMetaData['totalPages'] > $endNumber): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $video_galleryCustomerMetaData['totalPages'] ))) ?> "><?php echo $video_galleryCustomerMetaData['totalPages'];?></a>
<?php endif ?> 
<a href="<?php echo $video_galleryCustomerMetaData['nextPageLink'] ?>">Next</a>
<?php else: ?>
<?php endif ?>
<!-- /membership_access --><?php endif ?>

Anyone have any thoughts on getting this to work or a better solution?

Zick

By claire - November 7, 2014

Hi Zick

In this case, I think you're making this harder on yourself than it needs to be. You should be testing for the $CURRENT_USER membership type before loading the videos at all.

Back it all up a sec, and take a look at your initial code. You do have access to the $CURRENT_USER before you get to the getRecords function, so here's how I'd do it.

$params = array(
'tableName'   => 'video_gallery',
'perPage'     => '6',
'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);

if(@$CURRENT_USER['membership_user_type'] == 'Prospect')
{
  $params['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
  $params['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
  $params['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}

// now we're ready to go, load the records
list($video_galleryDealerRecords, $video_galleryDealerMetaData) = getRecords($params);

Basically, this should work regardless of whether there's a logged in user or not, and it should select the correct where clause as long as there is a logged in user, and that user has a membership user type set correctly. The getRecords function accepts an array of any kind, and although the CMSB Code Generator puts the array into the function itself, there's no need to do so in order to make it work - so you can just run whatever logic you need to run before getting any data, adjust the array accordingly, and hand that off to getRecords to have it pull the right information for you.

Let me know if this makes sense.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - November 7, 2014

Hey Claire,

Do you know if it's possible to apply your solution to the following load records listed below and if it's possible do you mind providing an example of how to do it?

        // load records products
  list($productsNavRecords, $selectedCategory) = getCategories(array(
    'tableName'   => 'products',
'categoryFormat' => 'showall'
//'categoryFormat' => 'onelevel' // showall, onelevel, twolevel
  ));
      // load records products
  list($productsSideMenuRecords, $selectedCategory) = getCategories(array(
    'tableName'   => 'products',
  ));

By claire - November 12, 2014

Even with a set of fields with different fields, the principle is exactly the same. Selectively changing the parameters before calling getRecords can be used in many different scenarios.

But these functions don't seem to include anything about the membership type, so can you let me know exactly what you want to check for?

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - November 12, 2014 - edited: November 12, 2014

Hey Claire,

The membership types are the same as with the previous solution you provided. Below is my attempt to make this work for "Category" section editors, but it throws the error seen below my code.

  $productsNavparams = array(
    'tableName'   => 'products',
'categoryFormat' => 'showall',
//'categoryFormat' => 'onelevel' // showall, onelevel, twolevel
'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);

if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$productsNavparams['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsNavparams['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsNavparams['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
// now we're ready to go, load the records
list($productsNavRecords, $selectedCategory) = getCategories($productsNavparams);


  $productsSideMenuparams = array(
    'tableName'   => 'products',
//'categoryFormat' => 'showall',
//'categoryFormat' => 'onelevel' // showall, onelevel, twolevel
'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);

if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$productsSideMenuparams['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsSideMenuparams['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsSideMenuparams['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
// now we're ready to go, load the records
list($productsSideMenuRecords, $selectedCategory) = getCategories($productsSideMenuparams);

Error message:

Category Viewer (products) errors
Unknown option 'where' specified
Valid option names are: (tableName, useSeoUrls, debugSql, selectedCategoryNum, categoryFormat, loadUploads, defaultCategory, rootCategoryNum, ulAttributes, ulAttributesCallback, liAttributesCallback, loadCreatedBy, ignoreHidden)

I also tried the following as well, but it produced the same error message. Basically boils down to my incompetence.

  $productsNavparams = getCategories(array(
    'tableName'   => 'products',
'categoryFormat' => 'showall',
//'categoryFormat' => 'onelevel' // showall, onelevel, twolevel
'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
));

if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$productsNavparams['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsNavparams['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsNavparams['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
// now we're ready to go, load the records
list($productsNavRecords, $productsNavMetaData) = getRecords($productsNavparams);


  $productsSideMenuparams = getCategories(array(
    'tableName'   => 'products',
//'categoryFormat' => 'showall',
//'categoryFormat' => 'onelevel' // showall, onelevel, twolevel
'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
));

if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$productsSideMenuparams['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsSideMenuparams['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$productsSideMenuparams['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
// now we're ready to go, load the records
list($productsSideMenuRecords, $productsNavMetaData) = getRecords($productsSideMenuparams);

By claire - November 12, 2014

Your problem there is using the getCategories function - this doesn't allow for a where clause, because that function doesn't have that functionality.

I can recommend to Dave that this be added to getCategories in the future, but for now you'd need to use getRecords here.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - November 12, 2014

Thanks for the help Claire!

By Mikey - November 17, 2014 - edited: November 17, 2014

Hey Claire - or anyone else who may have a solution to this question.

I need to add membership permission levels to what appears in the search engine results - based on weather the site user is the general public, or logged in and at the logged-in user's permission level. Below is my code at my first attempt which does not work. The changes I made are set in bold.

<?php
// search viewer code begins
      $searchOptions = array();
      $searchOptions['keywords'] = @$FORM['q'];
      $searchOptions['perPage']  = "6";
      $searchOptions['debugSql'] = "0";

      $searchTables = array();
  
  // Single Pages
  $searchTables['home_page'] = array(
        'viewerUrl'       => 'index.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','content'),
);

  // Single Pages
  $searchTables['contact'] = array(
        'viewerUrl'       => 'contact.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','content'),
      );
  
  // Category Pages
  $searchTables['products'] = array(
        'viewerUrl'       => 'product.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
  
  // Category Pages
  $searchTables['services'] = array(
        'viewerUrl'       => 'service.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
  
  // Category Pages
  $searchTables['sales'] = array(
        'viewerUrl'       => 'sales.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
  
  // Category Pages
  $searchTables['about_us'] = array(
        'viewerUrl'       => 'about.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
  
  // Multi Pages
  $searchTables['news'] = array(
        'viewerUrl'       => 'news.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','summary','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}
  
  // Multi Pages
  $searchTables['gallery'] = array(
        'viewerUrl'       => 'gallery.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','summary','content'),

'where'       => 'membership_access = "Public"' // this is the default - we assume there is no logged in user, so show only public videos.
);
if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; // specify a new where clause depending on the current user
}
if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchTables['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}
if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchTables['where'] = 'TRUE'; // dealers can see everything, so just set the where clause to TRUE
}

      list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);
  // search viewer code ends
?>
<?php require_once("include/maxWords.php"); ?>

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <input name="q" type="text" value="<?php echo htmlspecialchars(@$FORM['q']); ?>" size="40" />
    <input name="input" type="submit" value="Search" />
    
Search results for ( <?php echo htmlspecialchars(@$FORM['q']); ?> ) <br />
Results <b><?php echo htmlspecialchars(@$searchDetails['pageResultsStart']); ?></b> to <b><?php echo htmlspecialchars(@$searchDetails['pageResultsEnd']); ?></b> of <b><?php echo htmlspecialchars(@$searchDetails['totalRecords']); ?></b>.

    
      <?php if ($searchDetails['invalidPageNum']): ?>
     <p> Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/></p>
      <?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
    
    <strong>No records matched search query!</strong><br/>
    <?php elseif ($searchOptions['keywords'] == ""): ?>
    Enter a keyword to begin your search.<br />
    <?php endif ?>
    
<?php foreach ($searchRows as $record): ?>
    <a href="<?php echo $record['_link'] ?>"><?php echo htmlspecialchars($record['_title']); ?></a>

    <?php if ($record['_summary']): ?>
    <?php echo maxWords($record['_summary'], 60); ?>...
    <?php else: ?>
No description available for page.
    <?php endif ?>
    <a href="<?php echo $record['_link'] ?>">More &#8250;&#8250;</a>

    <?php endforeach ?>
  </form>

<?php  
if (@!$_GET['page']): $current_page = "1"; 
else: $current_page = $_GET['page'];    
endif;  ?> 

<?php 
$startNumber = max($current_page - 8, 1); 
$endNumber   = min($current_page + 8, $searchDetails['totalPages']); 
?>

<?php if ($searchDetails['prevPage']): ?>
<a href="<?php echo $searchDetails['prevPageLink'] ?>">Previous</a>&nbsp;&nbsp;
<?php if ($startNumber > '1'): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => '1' ))) ?> ">1</a>
<?php endif ?> 
<?php else: ?>
&nbsp;  
<?php endif ?>

<?php foreach (range($startNumber,$endNumber) as $page): ?>

<?php if ($page == $current_page): ?>
&nbsp;<?php echo $page; ?>&nbsp;
<?php else: ?> 
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>
<?php endif ?> 

<?php endforeach; ?> 

<?php if ($searchDetails['nextPage']): ?>
<?php if ($searchDetails['totalPages'] > $endNumber): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $searchDetails['totalPages'] ))) ?> "><?php echo $searchDetails['totalPages'];?></a>
<?php endif ?> 
&nbsp;&nbsp;<a href="<?php echo $searchDetails['nextPageLink'] ?>">Next</a>
<?php else: ?>   
&nbsp;
<?php endif ?>

Here's code for my second attempt, which also does not work either. The changes I made are set in bold.

<?php
// search viewer code begins
      $searchOptions = array();
      $searchOptions['keywords'] = @$FORM['q'];
      $searchOptions['perPage']  = "6";
      $searchOptions['debugSql'] = "0";
  
      $searchPermissions = array(
'where' => 'membership_access = "Public"' 
// this is the default - we assume there is no logged in user, so show only public videos.
);

if(@$CURRENT_USER['membership_user_type'] == 'Prospect') 
{
$searchPermissions['where'] = 'membership_access = "Public" OR membership_access = "Prospect"'; 
// specify a new where clause depending on the current user
}

if(@$CURRENT_USER['membership_user_type'] == 'Customer') 
{
$searchPermissions['where'] = 'membership_access = "Public" OR membership_access = "Customer"';
}

if(@$CURRENT_USER['membership_user_type'] == 'Dealer') 
{
$searchPermissions['where'] = 'TRUE'; 
// dealers can see everything, so just set the where clause to TRUE
}

      $searchTables = array();
  
  // Single Pages
  $searchTables['home_page'] = array(
        'viewerUrl'       => 'index.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','content'),
);

  // Single Pages
  $searchTables['contact'] = array(
        'viewerUrl'       => 'contact.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','content'),
      );
  
  // Category Pages
  $searchTables['products'] = array(
        'viewerUrl'       => 'product.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),
);
  
  // Category Pages
  $searchTables['services'] = array(
        'viewerUrl'       => 'service.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),
);
  
  // Category Pages
  $searchTables['sales'] = array(
        'viewerUrl'       => 'sales.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),
);
  
  // Category Pages
  $searchTables['about_us'] = array(
        'viewerUrl'       => 'about.php',
        'titleField'      => 'name',
        'summaryField'    => 'content',
        'searchFields'    =>  array('name','content'),
);
  
  // Multi Pages
  $searchTables['news'] = array(
        'viewerUrl'       => 'news.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','summary','content'),
);
  
  // Multi Pages
  $searchTables['gallery'] = array(
        'viewerUrl'       => 'gallery.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'searchFields'    =>  array('title','summary','content'),
);

      list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchPermissions, $searchOptions);
  // search viewer code ends
?>
<?php require_once("include/maxWords.php"); ?>

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <input name="q" type="text" value="<?php echo htmlspecialchars(@$FORM['q']); ?>" size="40" />
    <input name="input" type="submit" value="Search" />
    
Search results for ( <?php echo htmlspecialchars(@$FORM['q']); ?> ) <br />
Results <b><?php echo htmlspecialchars(@$searchDetails['pageResultsStart']); ?></b> to <b><?php echo htmlspecialchars(@$searchDetails['pageResultsEnd']); ?></b> of <b><?php echo htmlspecialchars(@$searchDetails['totalRecords']); ?></b>.

    
      <?php if ($searchDetails['invalidPageNum']): ?>
     <p> Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/></p>
      <?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
    
    <strong>No records matched search query!</strong><br/>
    <?php elseif ($searchOptions['keywords'] == ""): ?>
    Enter a keyword to begin your search.<br />
    <?php endif ?>
    
<?php foreach ($searchRows as $record): ?>
    <a href="<?php echo $record['_link'] ?>"><?php echo htmlspecialchars($record['_title']); ?></a>

    <?php if ($record['_summary']): ?>
    <?php echo maxWords($record['_summary'], 60); ?>...
    <?php else: ?>
No description available for page.
    <?php endif ?>
    <a href="<?php echo $record['_link'] ?>">More &#8250;&#8250;</a>

    <?php endforeach ?>
  </form>

<?php  
if (@!$_GET['page']): $current_page = "1"; 
else: $current_page = $_GET['page'];    
endif;  ?> 

<?php 
$startNumber = max($current_page - 8, 1); 
$endNumber   = min($current_page + 8, $searchDetails['totalPages']); 
?>

<?php if ($searchDetails['prevPage']): ?>
<a href="<?php echo $searchDetails['prevPageLink'] ?>">Previous</a>&nbsp;&nbsp;
<?php if ($startNumber > '1'): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => '1' ))) ?> ">1</a>
<?php endif ?> 
<?php else: ?>
&nbsp;  
<?php endif ?>

<?php foreach (range($startNumber,$endNumber) as $page): ?>

<?php if ($page == $current_page): ?>
&nbsp;<?php echo $page; ?>&nbsp;
<?php else: ?> 
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>
<?php endif ?> 

<?php endforeach; ?> 

<?php if ($searchDetails['nextPage']): ?>
<?php if ($searchDetails['totalPages'] > $endNumber): ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $searchDetails['totalPages'] ))) ?> "><?php echo $searchDetails['totalPages'];?></a>
<?php endif ?> 
&nbsp;&nbsp;<a href="<?php echo $searchDetails['nextPageLink'] ?>">Next</a>
<?php else: ?>   
&nbsp;
<?php endif ?>

By claire - November 19, 2014

Can you tell me what this function does?

searchMultipleTables($searchTables, $searchOptions);

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/