multiple records

29 posts by 4 authors in: Forums > CMS Builder
Last Post: October 12, 2010   (RSS)

By (Deleted User) - August 25, 2010

Hi Jason, this is the error I get when I try only show categories from one section:

Notice: Undefined variable: newsRecords in /home/smesacoz/public_html/layout2.php on line 288 Warning: Invalid argument supplied for foreach() in /home/smesacoz/public_html/layout2.php on line 288 Notice: Undefined variable: newsMetaData in /home/smesacoz/public_html/layout2.php on line 314 Notice: Undefined variable: newsRecords in /home/smesacoz/public_html/layout2.php on line 316 No records were found!

Notice: Undefined variable: newsMetaData in /home/smesacoz/public_html/layout2.php on line 321 Notice: Undefined variable: newsMetaData in /home/smesacoz/public_html/layout2.php on line 327


This is my code:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/smesacoz/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."); }

list($financeRecords,$financeMetaData)=getRecords(array(
'tableName' => 'news',
'allowSearch' => false,
'where' => "category = 'finance'",
));

?>


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

<a class="news" href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<div class="spacer"></div>

<!-- Display Image -->
<div class="img">
<?php foreach ($record['image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a>

<?php endif ?>
<?php endforeach ?>
</div>
<!-- Display Image -->

<?php echo $record['intro'] ?>
<div class="spacer"></div>
<?php endforeach ?>

<?php if ($newsMetaData['invalidPageNum']): ?>
Results page '<?php echo $newsMetaData['page']?>' not found, <a href="<?php echo $newsMetaData['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/><br/>
<?php elseif (!$newsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

<!-- Display Page Links -->
<?php if ($newsMetaData['prevPage']): ?>
<a href="<?php echo $newsMetaData['prevPageLink'] ?>"><img src="images/prevrightdark.png" alt="" width="20" height="20" border="0" /></a>
<?php else: ?>
<img src="images/prevright.png" width="20" height="20" alt="" />
<?php endif ?>

<?php if ($newsMetaData['nextPage']): ?>
<a href="<?php echo $newsMetaData['nextPageLink'] ?>"><img src="images/nextrightdark.png" alt="" width="20" height="20" border="0" /></a>
<?php else: ?>
<img src="images/nextright.png" width="20" height="20" alt="" />
<?php endif ?>
<!-- Display Page Links -->

Re: [smesa] multiple records

By Jason - August 25, 2010

Hi,

The error is being caused because your using $financeRecords and $financeMetaData in your list() function. The quickest and easiest fix would be to change this to $newsRecords and $newsMetaData like this:

list($newsRecords,$newsMetaData)=getRecords(array(
'tableName' => 'news',
'allowSearch' => false,
'where' => "category = 'finance'",
));


As for your other question, you can turn your list to a drop down like this:

<select name="category">
<option value="">All Articles</option>
<?php echo getSelectOptionsFromTable('categories','num','name',@$_REQUEST['category'],false);?>
</select>


Note, this assumes that your categories are coming from a table called "categories", if not, you'll have to change the first parameter. Also, this will create your drop down list, but it won't actually make it do a search.

Hope this gets you started.
---------------------------------------------------
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 (Deleted User) - August 27, 2010

Hi Jason,

This is working well. Now comes my next problem:

I'm using Jquery Tabs on my site. There are a total of 3 tabs - each belongs to one table but must hold 3 different categories (one per tab).

Let's just call them event1, event2 and event 3.

This is the code in the top of my page:

// load events1
list($eventsRecords, $eventsMetaData)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '1'",
'perPage' => '5',
));

// load events2
list($eventsRecords, $eventsMetaData)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '2'",
'perPage' => '5',
));

// load events3
list($eventsRecords, $eventsMetaData)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '3'",
'perPage' => '5',
));

These are the DIV id's to bring up the tabs:

<div id="first">
<?php foreach ($eventsRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo $record['introduction'] ?>
<?php endforeach ?>
</div>

<div id="second">
This is where I need category event 2 to go...
</div>

<div id="third">
This is where I need category event 3 to go...
</div>

The question is how do I pull different categories from one table and display them seperately? Is there some type of category reference I can use? If I use the same code as used in the first DIV then the same events show up on all 3 tabs.

Hope you can help.

Kind regards
Shawn

Re: [smesa] multiple records

By Jason - August 27, 2010

Hi Shawn,

What's happening is that your querying the database 3 times to get 3 different sets of records based on category. The problem is that you're using the same variable names each time ($eventsRecords), so as you go through each query, it's overwriting the previous results. What's you're probably experiencing is that the content in <div id="first"> has records for category 3 in it.

Trying changing the variable names like this:

Hi Jason,

This is working well. Now comes my next problem:

I'm using Jquery Tabs on my site. There are a total of 3 tabs - each belongs to one table but must hold 3 different categories (one per tab).

Let's just call them event1, event2 and event 3.

This is the code in the top of my page:

// load events1
list($eventsRecords1, $eventsMetaData1)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '1'",
'perPage' => '5',
));

// load events2
list($eventsRecords2, $eventsMetaData2)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '2'",
'perPage' => '5',
));

// load events3
list($eventsRecords3, $eventsMetaData3)=getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'where' => "category = '3'",
'perPage' => '5',
));


Now you can output the records for each category separately:

<div id="first">
<?php foreach ($eventsRecords1 as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo $record['introduction'] ?>
<?php endforeach ?>
</div>

<div id="second">
<?php foreach ($eventsRecords2 as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo $record['introduction'] ?>
<?php endforeach ?>
</div>

<div id="third">
<?php foreach ($eventsRecords3 as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo $record['introduction'] ?>
<?php endforeach ?>
</div>


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/

Re: [smesa] multiple records

By Jason - October 7, 2010

Hi Shawn,

If you are using version 2.04 or higher, you can use the "label" pseudo field to display a list fields label instead of the value. It would work like this:

<?php echo $record['category:label'];?>

That should do it. Let me know if this works out for you.
Glad to hear that everything else is going well.
---------------------------------------------------
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 (Deleted User) - October 7, 2010

Works like a charm. Thanks Jason!

Re: [smesa] multiple records

By (Deleted User) - October 10, 2010

Hi Jason,

Just wanted to ask how one would put together a contact feedback form or competition entry form? Or is this something that CMS Builder doesn't do?

regards
Shawn

Re: [smesa] multiple records

By Jason - October 12, 2010

Hi Shawn,

Yes, CMS Builder can definitely handle that. What you would need to do first is to create the sections in CMS Builder that you would want to store the information in. After that, set up your HTML form to collect the data. Once you submit it, you'll need to create the MySQL INSERT statements to write it to the database.

Hope this gets you started. Let me know if you have any other questions.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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