Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2014

By Mohaukla - September 21, 2014 - edited: September 22, 2014

I have a list "resource_documents" of uploaded documents that I added another list "resource_type"  inside it to identify what type of document it is.

I need to make a list of each depending on the type of document it is.

So here is the list of types (lable = title)

Case Study 
White Paper
Newsletter
Form
Webinar
Recorded Webinar
Sample Product Report

So if I need a list of documents that are just Case Studies or whatever.... what would that look like?

<?php foreach ($resource_documentsRecords as $record): ?>

if resource_type:label = Case Study 

<?php endforeach ?>

Im not sure if it needs an if statement or if that can be worked out inside the foreach statement

Thanks in advance

And just an FYI this will lead into a similar followup question.

Michael Moyers

Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.

"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Hi Michael

This depends on whether you need all the records in that section and you're just sorting them, or whether you just want Case Studies.

Getting them all and then sorting them would look something like this:

list($resourceDocsRecords, $resourceDocsRecordsMeta) = getRecords(array(
    'tableName' => 'resource_documents',
    'allowSearch' => false
));

$resources = array();

foreach ($resourceDocsRecords as $doc) {
    $resources[$doc['resource_type:label']][] = $doc;
}

So this gives you a two level array of the records, sorted by their type, then you output them like so:

<?php foreach ($resources as $type => $record): ?>
    <?php if($type == 'Case Study') : ?>
        <h1 class="casestudy"><?php echo $record['title']; ?></h1>
        <?php echo $record['description']; ?>
        ... echo more record stuff for case studies here...
    <?php elseif ($type == 'White Paper) : ?>
        <h1 class="whitepaper"><?php echo $record['title']; ?></h1>
        <?php echo $record['description']; ?>
        ... echo more record stuff for white papers here...
    <?php else : ?>
        <h1 class="default"><?php echo $record['title']; ?></h1>
        <?php echo $record['description']; ?>
        ... echo more default stuff here...
    <?php endif; ?>
<?php endforeach ?>

Hopefully you get the idea. Just make sure you change the variable names - I've inserted title and description here but I assume you have more than that.

If you just want a list of Case Studies, then all you need is an extra parameter added to the getRecords function, like so:

list($resourceDocsRecords, $resourceDocsRecordsMeta) = getRecords(array(
    'tableName' => 'resource_documents',
    'allowSearch' => false,
    'where' => 'resource_type = "Case Study"' // insert the VALUE, not the label, of the resource type you want here.
));

Does this all make sense?

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

Claire Ryan
interactivetools.com

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

That is great thanks! Based on what you have shown me I understand a little better.

My next question would be how to come from a category page to a specific type list page

If I make a foreach loop to create a list of documents by types.

So I would start on the category page (lets say "resources.php") with:

  list($resource_typeRecords, $resource_typeMetaData) = getRecords(array(
    'tableName'   => 'resource_type',
    'loadUploads' => false,
    'allowSearch' => false,
  ));
$type = mysql_select ('resource_type');

And then show the categories in columns: 

  <section class='white trans' id='content'>
    <?php foreach ($resource_typeRecords as $record): ?>
      <div class='col-md-12 col-md-offset-0'>
        <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-search'></span>
            <?php echo htmlencode($record['title']) ?>
          </h3>
          <p class='small'><?php echo $record['content']; ?></p>
          <a class='btn btn-default btn-md'>
            <span class='fa fa-caret-right'></span>
            <a href="categorytype.php?type=<?php echo $type['title'];?>">Read more</a>
          </a>
        </div>
      </div>
   <?php endforeach ?>
  </section>

SOOO

If I want the link to be built to go to a single category list page (I suppose I would NOT set that up in the "viewer links tab" ) using the "title" in the link (example categorytype.php?type=)

And then what the code look like on the receiving list page (categorytype.php) to understand that we are looking for a list of resources based on the type in the link

I am only guessing  on this

  list($resource_documentsRecords, $resource_documentsMetaData) = getRecords(array(
    'tableName'   => 'resource_documents',
    'loadUploads' => false,
    'allowSearch' => true,
  ));

I think I am close on some but not everything.

Thanks for your help

Michael Moyers

Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.

"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Hi Michael

This line here:

<a href="categorytype.php?type=<?php echo $type['title'];?>">Read more</a>

This isn't going to get you anything. The title is likely a string with spaces and whatnot, so it's not going to produce a valid link. Change it like so:

<a href="categorytype.php?type=<?php echo $type['num'];?>">Read more</a>

Then on the categorytype.php page, change getRecords like so:

list($resource_documentsRecords, $resource_documentsMetaData) = getRecords(array(
    'tableName'   => 'resource_documents',
    'loadUploads' => false,
    'where'       => 'type = '.mysql_escape(@$_REQUEST['type']),
    'allowSearch' => true,
  ));

I'm assuming that 'type' is the right fieldname, but if not, change it to whatever it should be. What you need to pass in the link is whatever is stored in the documents table that identifies the particular records you want to show.

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

Claire Ryan
interactivetools.com

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

Hi Michael

You'll have to see if the $type includes what you think it does just as that echo statement is being processed.

Just before that line, enter this:

<?php showme($type); ?>

Take a look at the output on the page.

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

Claire Ryan
interactivetools.com

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

OK maybe I need to call you on this one LOL

Inserted your Show me code:

      <?php foreach ($resource_typeRecords as $record): ?>
        <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-<?php echo htmlencode($record['resource_type_icon']) ?>'></span>
            <?php echo htmlencode($record['title']) ?>
          </h3>
          <p class='small'><?php echo strip_tags($record['content']); ?></p>
          <?php showme($type); ?>
          <a class='btn btn-default btn-md' href="categorytype.php?type=<?php echo $type['num'];?>">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
      <?php endforeach ?>

and I get this in the returned source code:

Sorry for the lengthy code here but this is one trip through the above loop.

  <div class='col-md-3 service'>    
   <h3>
            <span class='fa fa-search'></span>
            Case Study          </h3>
          <p class='small'>Learn first-hand how we help our clients drive important business results.</p>
          <xmp>Array
(
    [0] => Array
        (
            [num] => 1
            [createdDate] => 2014-09-22 01:12:33
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 70
            [title] => Case Study
            [content] => <p>Learn first-hand how we help our clients drive important business results.</p>
            [resource_type_icon] => search
            [_tableName] => resource_type
        )

    [1] => Array
        (
            [num] => 2
            [createdDate] => 2014-09-22 01:12:59
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:15:00
            [updatedByUserNum] => 1
            [dragSortOrder] => 10
            [title] => Sample Product Report
            [content] => <p>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
            [resource_type_icon] => file-text-o
            [_tableName] => resource_type
        )

    [2] => Array
        (
            [num] => 5
            [createdDate] => 2014-09-22 01:15:24
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:13:13
            [updatedByUserNum] => 1
            [dragSortOrder] => 40
            [title] => Form
            [content] => <p>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
            [resource_type_icon] => list-ol
            [_tableName] => resource_type
        )

    [3] => Array
        (
            [num] => 6
            [createdDate] => 2014-09-22 01:15:58
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:12:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 50
            [title] => Newsletter
            [content] => <p>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
            [resource_type_icon] => newspaper-o
            [_tableName] => resource_type
        )

    [4] => Array
        (
            [num] => 7
            [createdDate] => 2014-09-22 01:16:44
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:56
            [updatedByUserNum] => 1
            [dragSortOrder] => 60
            [title] => White Paper
            [content] => <p>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
            [resource_type_icon] => file-o
            [_tableName] => resource_type
        )

)
</xmp>          <a class='btn btn-default btn-md' href="categorytype.php?type=
Notice: Undefined index: num in /data/13/0/142/86/142086/user/143888/htdocs/newsite/pages/resources.php on line 151
">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
              <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-file-o'></span>
            White Paper          </h3>
          <p class='small'>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
          <xmp>Array
(
    [0] => Array
        (
            [num] => 1
            [createdDate] => 2014-09-22 01:12:33
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 70
            [title] => Case Study
            [content] => <p>Learn first-hand how we help our clients drive important business results.</p>
            [resource_type_icon] => search
            [_tableName] => resource_type
        )

    [1] => Array
        (
            [num] => 2
            [createdDate] => 2014-09-22 01:12:59
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:15:00
            [updatedByUserNum] => 1
            [dragSortOrder] => 10
            [title] => Sample Product Report
            [content] => <p>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
            [resource_type_icon] => file-text-o
            [_tableName] => resource_type
        )

    [2] => Array
        (
            [num] => 5
            [createdDate] => 2014-09-22 01:15:24
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:13:13
            [updatedByUserNum] => 1
            [dragSortOrder] => 40
            [title] => Form
            [content] => <p>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
            [resource_type_icon] => list-ol
            [_tableName] => resource_type
        )

    [3] => Array
        (
            [num] => 6
            [createdDate] => 2014-09-22 01:15:58
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:12:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 50
            [title] => Newsletter
            [content] => <p>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
            [resource_type_icon] => newspaper-o
            [_tableName] => resource_type
        )

    [4] => Array
        (
            [num] => 7
            [createdDate] => 2014-09-22 01:16:44
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:56
            [updatedByUserNum] => 1
            [dragSortOrder] => 60
            [title] => White Paper
            [content] => <p>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
            [resource_type_icon] => file-o
            [_tableName] => resource_type
        )

)
</xmp>          <a class='btn btn-default btn-md' href="categorytype.php?type=
Notice: Undefined index: num in /data/13/0/142/86/142086/user/143888/htdocs/newsite/pages/resources.php on line 151
">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
              <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-newspaper-o'></span>
            Newsletter          </h3>
          <p class='small'>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
          <xmp>Array
(
    [0] => Array
        (
            [num] => 1
            [createdDate] => 2014-09-22 01:12:33
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 70
            [title] => Case Study
            [content] => <p>Learn first-hand how we help our clients drive important business results.</p>
            [resource_type_icon] => search
            [_tableName] => resource_type
        )

    [1] => Array
        (
            [num] => 2
            [createdDate] => 2014-09-22 01:12:59
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:15:00
            [updatedByUserNum] => 1
            [dragSortOrder] => 10
            [title] => Sample Product Report
            [content] => <p>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
            [resource_type_icon] => file-text-o
            [_tableName] => resource_type
        )

    [2] => Array
        (
            [num] => 5
            [createdDate] => 2014-09-22 01:15:24
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:13:13
            [updatedByUserNum] => 1
            [dragSortOrder] => 40
            [title] => Form
            [content] => <p>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
            [resource_type_icon] => list-ol
            [_tableName] => resource_type
        )

    [3] => Array
        (
            [num] => 6
            [createdDate] => 2014-09-22 01:15:58
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:12:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 50
            [title] => Newsletter
            [content] => <p>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
            [resource_type_icon] => newspaper-o
            [_tableName] => resource_type
        )

    [4] => Array
        (
            [num] => 7
            [createdDate] => 2014-09-22 01:16:44
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:56
            [updatedByUserNum] => 1
            [dragSortOrder] => 60
            [title] => White Paper
            [content] => <p>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
            [resource_type_icon] => file-o
            [_tableName] => resource_type
        )

)
</xmp>          <a class='btn btn-default btn-md' href="categorytype.php?type=
Notice: Undefined index: num in /data/13/0/142/86/142086/user/143888/htdocs/newsite/pages/resources.php on line 151
">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
              <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-list-ol'></span>
            Form          </h3>
          <p class='small'>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
          <xmp>Array
(
    [0] => Array
        (
            [num] => 1
            [createdDate] => 2014-09-22 01:12:33
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 70
            [title] => Case Study
            [content] => <p>Learn first-hand how we help our clients drive important business results.</p>
            [resource_type_icon] => search
            [_tableName] => resource_type
        )

    [1] => Array
        (
            [num] => 2
            [createdDate] => 2014-09-22 01:12:59
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:15:00
            [updatedByUserNum] => 1
            [dragSortOrder] => 10
            [title] => Sample Product Report
            [content] => <p>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
            [resource_type_icon] => file-text-o
            [_tableName] => resource_type
        )

    [2] => Array
        (
            [num] => 5
            [createdDate] => 2014-09-22 01:15:24
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:13:13
            [updatedByUserNum] => 1
            [dragSortOrder] => 40
            [title] => Form
            [content] => <p>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
            [resource_type_icon] => list-ol
            [_tableName] => resource_type
        )

    [3] => Array
        (
            [num] => 6
            [createdDate] => 2014-09-22 01:15:58
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:12:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 50
            [title] => Newsletter
            [content] => <p>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
            [resource_type_icon] => newspaper-o
            [_tableName] => resource_type
        )

    [4] => Array
        (
            [num] => 7
            [createdDate] => 2014-09-22 01:16:44
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:56
            [updatedByUserNum] => 1
            [dragSortOrder] => 60
            [title] => White Paper
            [content] => <p>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
            [resource_type_icon] => file-o
            [_tableName] => resource_type
        )

)
</xmp>          <a class='btn btn-default btn-md' href="categorytype.php?type=
Notice: Undefined index: num in /data/13/0/142/86/142086/user/143888/htdocs/newsite/pages/resources.php on line 151
">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
              <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-file-text-o'></span>
            Sample Product Report          </h3>
          <p class='small'>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
          <xmp>Array
(
    [0] => Array
        (
            [num] => 1
            [createdDate] => 2014-09-22 01:12:33
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 70
            [title] => Case Study
            [content] => <p>Learn first-hand how we help our clients drive important business results.</p>
            [resource_type_icon] => search
            [_tableName] => resource_type
        )

    [1] => Array
        (
            [num] => 2
            [createdDate] => 2014-09-22 01:12:59
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:15:00
            [updatedByUserNum] => 1
            [dragSortOrder] => 10
            [title] => Sample Product Report
            [content] => <p>The essence of relationships, especially High Performance Teams, is communication. It is through communication that people share information, make decisions, solve problems and accomplish their day-to-day jobs.</p>
            [resource_type_icon] => file-text-o
            [_tableName] => resource_type
        )

    [2] => Array
        (
            [num] => 5
            [createdDate] => 2014-09-22 01:15:24
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:13:13
            [updatedByUserNum] => 1
            [dragSortOrder] => 40
            [title] => Form
            [content] => <p>A collection of forms to help you analyze and strategize different aspects of your business. Download and use them as they apply to your situation.</p>
            [resource_type_icon] => list-ol
            [_tableName] => resource_type
        )

    [3] => Array
        (
            [num] => 6
            [createdDate] => 2014-09-22 01:15:58
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:12:35
            [updatedByUserNum] => 1
            [dragSortOrder] => 50
            [title] => Newsletter
            [content] => <p>Our archive of newsletters with important topics about business practices and articals that make a difference to managers and employees.</p>
            [resource_type_icon] => newspaper-o
            [_tableName] => resource_type
        )

    [4] => Array
        (
            [num] => 7
            [createdDate] => 2014-09-22 01:16:44
            [createdByUserNum] => 1
            [updatedDate] => 2014-09-27 07:11:56
            [updatedByUserNum] => 1
            [dragSortOrder] => 60
            [title] => White Paper
            [content] => <p>See our collected studies of real life stratagies used by our clients and other successful businesses.</p>
            [resource_type_icon] => file-o
            [_tableName] => resource_type
        )

)
</xmp>          <a class='btn btn-default btn-md' href="categorytype.php?type=
Notice: Undefined index: num in /data/13/0/142/86/142086/user/143888/htdocs/newsite/pages/resources.php on line 151
">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>

It seems to be repeating all the records for each trip through the loop.

I sure hope this gives you an idea on whats going on.

Michael Moyers

Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.

"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Hi Michael

I know it looks intimidating but this makes perfect sense - your $type variable is an array of arrays, not a single array. I'm not sure if you need it, assuming the $record holds some reference to the type's num.

How about this:

<?php foreach ($resource_typeRecords as $record): ?>
        <div class='col-md-3 service'>
          <h3>
            <span class='fa fa-<?php echo htmlencode($record['resource_type_icon']) ?>'></span>
            <?php echo htmlencode($record['title']) ?>
          </h3>
          <p class='small'><?php echo strip_tags($record['content']); ?></p>
          <a class='btn btn-default btn-md' href="categorytype.php?type=<?php echo $record['type'];?>">
            <span class='fa fa-caret-right'></span>
             Read more
          </a>
        </div>
      <?php endforeach ?>

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

Claire Ryan
interactivetools.com

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