22 posts by 3 authors in: Forums > CMS Builder
Last Post: February 19, 2014   (RSS)

on this same note... if I have a status called "archived".  Can it be set so if any stallion's status = "archived" then it won't show on this page?  I'll put the entire "archived" stallions on their own page. 

By Chris - January 27, 2014

Hi Tina,

Can you attach the PHP source code for these pages so we can take a look at what's going on?

You can add status != "archived" to your getRecords() where clause to prevent them from showing up at all. When you post your code, I can provide an example.

Finally, are you adverse to using <div style="float: left;"> instead of tables? Using divs can make your PHP code for multiple-column layouts can be much simpler, since you just throw a <div style="clear: both;"> on the end rather than having to keep track of what column you're in and deciding between </td><td> and </td></tr><tr><td>.

Please post your code. :)

All the best,
Chris

I'm so glad I checked this again. I replied yesterday but it's not here. it's happened to everything I've touched for at least a week now. 

PHP source code is attached.

I am not against using divs instead of tables. I tried it on a few tests but then the list goes completely horizontal in 1 row rather than 2 rows like the breed list ( http://www.superiorequinesires.com/stallion-list6breeds.php ) . I'm sure it's really obvious. :( 

By Chris - January 29, 2014 - edited: January 29, 2014

Hi Tina,

You're having trouble with our forum deleting your posts? If so, please shoot me an email at chris@interactivetools.com and we'll look into that!

Here's an example of how to use floated divs instead of tables for two-column data. If you like, throw this in an HTML page and check it out in your browser. But this is just for reference, I've addressed your </tr><tr> table approach in the next message below.

<style>
.container { width: 205px; } /* container width should be cols * cell width, but add a few extra pixels for IE -- as long as it's less than (cols+1) * cell width, you're safe! */
.cell      { width: 100px; float: left; }
.clear     { clear: both; }
</style>

<h2>Container Start</h2>
<div class="container">
  <div class="cell">Testing...</div>
</div>
<div class="clear"></div>

<h2>Container Start</h2>
<div class="container">
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
</div>
<div class="clear"></div>

<h2>Container Start</h2>
<div class="container">
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
</div>
<div class="clear"></div>

<h2>Container Start</h2>
<div class="container">
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
</div>
<div class="clear"></div>

<h2>Container Start</h2>
<div class="container">
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
  <div class="cell">Testing...</div>
</div>
<div class="clear"></div>

All the best,
Chris

By Chris - January 29, 2014

Your </tr><tr> code will work fine, but you'll need to reset $count to zero before every foreach. The problem is that the code is "remembering" the column count from the last table, so it'll sometimes jump down to the second row after the first cell. Just add this line before every foreach:

<?php $count = 0; ?>
<?php foreach ($stallion_listRecords as $record): ?>

Your approach of filtering records with if ($record['status'] == ... should also work fine, but the problem is probably that the data isn't exactly what you're expecting. Inspecting the data in your records might show what the problem is. Can you try adding this one line of code right before your include_header.php include?

<?php if (@$_REQUEST['debug']) { showme($stallion_listRecords); exit; } ?>
<?php include "include_header.php"; ?>

Then we can go to http://www.superiorequinesires.com/stallion-list6status.php?debug=1 and see what the status and breed fields are set to.

If that's not possible for whatever reason, please let me know and I'll try and think of another approach.

All the best,
Chris

Hi Chris, 

Thanks so much! Maybe it's because everything I've touch for about a week and a half has gone crazy... I'm really close with this but obvious did something wrong: 
I need to rows for content display. Top row is the stallions name/link. Bottom row is price, status, etc.
Am I making this harder than it has to be? :) 

Also, Is there any way possible to change the background cell color if a Stallion's status is marked as "new'?  (request from client)

Thanks so much! Tina

<style>
.container { width: 205px; } /* container width should be cols * cell width, but add a few extra pixels for IE -- as long as it's less than (cols+1) * cell width, you're safe! */
.cell      { width: 100px; float: left; }
.clear     { clear: both; }
</style>

<?php foreach ($stallion_listRecords as $record): ?>
<?PHP if ($record['breed'] == "Brandenburg"): ?>
<div class="container">
   <div class="cell">   
      <div><h3>   
         <?php if($record['stallion_url']) : ?> <a href="<?php echo $record['stallion_url']; ?>"><?php echo htmlencode($record['title']); ?></a>
         <?php else : ?> <a href="<?php echo $record['_link']; ?>">
         <?php echo htmlencode($record['title']); ?></a>
         <?php endif; ?> </h3>
      </div>
    <div>   
         <?php echo htmlencode($record['price']) ?>             
         <?php if ($record['status'] == 'New') : ?><img src="http://www.superiorequinesires.com/images/icon-star-new-stallions.png" width="26" height="26" />             
         <?PHP endif ?>             
         <?php if ($record['status'] == 'Special') : ?><img src="http://www.superiorequinesires.com/images/icon-star-new-stallions.png" width="26" height="26" />             
         <?PHP endif ?>             
         <?php echo join(', ', $record['status:labels']); ?> <?php if (!$stallion_listRecords): ?> No records were found!             
         <?php endif ?>
     </div>
   </div>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php endforeach ?>

Oops. Here's the page so you can see the result of that:

http://www.superiorequinesires.com/stallion-list7breeds.php

ABOUT THE STATUS DISPLAY PAGE:  http://www.superiorequinesires.com/stallion-list6status.php

I added the debug code
http://www.superiorequinesires.com/stallion-list6status.php?debug=1

I've attached a screenshot of my status list plus the list6status.php just in case. 

Thanks again for your help! it's much appreciated. 

Hi csdesign,

I think I've found out why your list items have stopped displaying. When you have a single list item, CMS Builder stores the value without any formatting, for example "1" or "In-Stock". But if you have a multi checkbox list, it stores the values in a tab separated list for example "    In-stock     " or "    In-stock     Special    ". So instead of using equal to, you should search for the value instead:

<style>
.container { width: 205px; } /* container width should be cols * cell width, but add a few extra pixels for IE -- as long as it's less than (cols+1) * cell width, you're safe! */
.cell      { width: 100px; float: left; }
.clear     { clear: both; }
</style>

<?php foreach ($stallion_listRecords as $record): ?>
<?PHP if ($record['breed'] == "Brandenburg"): ?> 
<div class="container"> 
   <div class="cell">    
      <div><h3>    
         <?php if($record['stallion_url']) : ?> <a href="<?php echo $record['stallion_url']; ?>"><?php echo htmlencode($record['title']); ?></a> 
         <?php else : ?> <a href="<?php echo $record['_link']; ?>">
         <?php echo htmlencode($record['title']); ?></a> 
         <?php endif; ?> </h3>
      </div> 
    <div>    
         <?php echo htmlencode($record['price']) ?>             
         <?php if (strpos($record['status'],"\tNew\t") !== false) : ?><img src="http://www.superiorequinesires.com/images/icon-star-new-stallions.png" width="26" height="26" />             
         <?PHP endif ?>             
         <?php if (strpos($record['status'],"\tSpecial\t") !== false) : ?><img src="http://www.superiorequinesires.com/images/icon-star-new-stallions.png" width="26" height="26" />             
         <?PHP endif ?>             
         <?php echo join(', ', $record['status:labels']); ?> <?php if (!$stallion_listRecords): ?> No records were found!             
         <?php endif ?> 
     </div> 
   </div> 
</div> 
<div class="clear"></div> 
<?php endif; ?>
<?php endforeach ?>

So the strpos (http://ca2.php.net/strpos) function is used to search a string for the contents of another string. In this case we're searching the $record['status'] field to see if it contains new or special, if it doesn't then the item is skipped.

The \t values ensure that new/special starts and ends with tab spaces, to ensure we only return the value new and not newest, or another value that contains new.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas
PHP Programmer - interactivetools.com