Details page with picture links to other in same category

13 posts by 2 authors in: Forums > CMS Builder
Last Post: September 17, 2013   (RSS)

By thenetgirl - September 9, 2013

Example page - http://greens.exedor.us/projectsdetail.php?Copy-4-Baldwin-Hills-Pool-House-4

on the bottom of this page I need to add image/links to other in the same category  in this case Residential

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

<?php foreach ($projectsRecord['snapshot'] as $index => $upload): ?>
<?php if ($projectsRecord['project_type:label'] == 'Residential'): ?>

<a href="<?php echo $projectsRecord['_link'] ?>">
<img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" /></a>
<div style="color:#333333; font:Verdana; text-transform: uppercase"><b>
<?php echo htmlencode($projectsRecord['title']) ?></b></font></div>

<?php $maxCols=5; if (@++$count % $maxCols == 0): ?>
<?php endif; ?>
<?php endif; ?>

<?php endforeach ?>

I think what I am missing goes in the header part and not quite sure how to get the right stuff in there.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/greensul/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'projects'
list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$projectsRecord = @$projectsRecords[0]; // get first record
if (!$projectsRecord) { dieWith404("Record not found!"); } // show error message if no record found

$title = "Greensulate Projects - Green roofs, green walls, and sustainable building consulting";

?>

Patricia

www.thenetgirl.com
Attachments:

projectsdetail.php 9K

By Jason - September 10, 2013

Hi,

No problem.  So, if I'm understanding your code correctly, you on the project detail page you want to load all of the projects that have the same project_type as the project being displayed on the detail page (leaving out the currently displayed project as to not duplicate).  Is that right?

What's happening here is that $proejctsRecords will only ever load a single record.  Also, it is currently set to always load the first record it finds in the projects section, regardless of what's being passed in the URL.  What we need to do here would be to change your first getRecords call to load the correct record, and then have a second getRecords call to load all the related projects.

Try this:

  // load record from 'projects'
  list($projectsRecords, $projectsMetaData) = getRecords(array(
    'tableName'   => 'projects',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $projectsRecord = @$projectsRecords[0]; // get first record
  if (!$projectsRecord) { dieWith404("Record not found!"); } // show error message if no record found
  
  list($relatedProjects, $relatedProjectsMetaData) = getRecords(array(
    'tableName'  =>  'projects',
    'allowSearch'  =>  false,
    'where'        =>  "project_type = '".mysql_escape($projectsRecord['project_type'])."' AND num != '".intval($projectsRecord['num'])."'",
  ));

Give this a try and let me know if this returns the results you were expecting.

Hope this helps,

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By thenetgirl - September 10, 2013

NO just gave me a big fat error no show on the browser

Patricia

www.thenetgirl.com

By Jason - September 10, 2013

Hi,

Can you please attach the entire PHP file so I can take a closer look at the code?

Thanks

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By thenetgirl - September 10, 2013

Here you go just added the code and thats it ..not really sure how to go about doing anything to it.

Patricia

www.thenetgirl.com
Attachments:

projectsdetail_001.php 9K

By Jason - September 10, 2013

Hi,

The first thing I noticed is that your new file is missing the connection to viewer_functions.php at the top


  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/greensul/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

This is the most likely cause of the error you experienced, since there are no PHP syntax errors on the page.

I also noticed that in the "Related Projects" section of your page, you are still outputting the value from $projectsRecords instead of the new $relatedProjects variable.

Hope this helps,

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By thenetgirl - September 10, 2013

ah ha thanks let me fix all that

Patricia

www.thenetgirl.com

By thenetgirl - September 10, 2013

Yiiiiiiiiiiiiiiiiiiiiiiippppppppppppie  just got to get them in a row  think I can do that 

http://greens.exedor.us/1projectsdetail.php?Copy-4-Baldwin-Hills-Pool-House-4

I do have a stupid question I want a real list  <li> with bullet points on  cant seem to find that any where  - 

<ul> <li> <font face="Verdana" color="#000"><b><?php echo join(', ', $projectsRecord['size_type:values']); ?></li><br>
&nbsp;</b></font> </ul>

SIZE/TYPE

  • 1500 sf hybrid
  • Built-up system

And can you explain when you values and when you use labels < cant seem to get that.

THANKS JASON :-)

Patricia

www.thenetgirl.com

By Jason - September 10, 2013

Hi,

Glad to hear that's working out for you now.

Great question about the difference between those 2 different pseudo fields.  Hopefully this will help clarify how it works.

When working with lists, getRecords() gives us 2 different sets of pseudo fields.  In the case of single value drop down lists or radio buttons, we get :value and :label.  When we are using multi-value drop downs or checkbox lists, we get :values and :labels.  The only difference between these two are :value/:label are single values, where :values/:labels are arrays.

The value pseudo field is the value that is actually stored in the database.  the label pseudo field is the value that we use for display.  So, for example, if we set up a list where we are pulling in values from another section (http://www.interactivetools.com/kb/article.php?Populate-a-list-field-from-another-section-15), we can set the value of the list to be "num" and the label to be "title".  

Generally, when trying to display information, we will normally want to use the label(s) field.  In your case, since :labels is an array, we can use a foreach loop to display everything in a <ui> list like this:

<ul>
  <?php foreach ($projectsRecord['size_type:labels'] as $label): ?>
    <li><font face="Verdana" color="#000"><b><?php echo $label;?></b></font></li>
  <?php endforeach ?>
</ul>

This will give you an <ul> list all the labels of selected values of size_type for that record.

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By thenetgirl - September 10, 2013

THANKS JASON :-)

Patricia

www.thenetgirl.com