 |

Perchpole
User
Jul 1, 2008, 3:37 AM
Post #1 of 18
(1118 views)
Shortcut
|
|
'Where' to find an answer!
|
Can't Post
|
|
I'm trying to develop a random image display for my client who makes and sells military models. I want to pad out his home page by loading a new image every time a visitor opens the page. The data is drawn straight from the product catalogue (so no need to enter the info twice). The only problem is that some of the products don't have images. That means every once in a while the rotator will load a blank page - which won't look good. So, I'd like to use a 'where' clause to ensure the page only displays records that do have images. Trouble is, I can't work out what code to use... $options['where'] = 'xxx'; (NB: This site still uses the old CMS Builder code format) The upload field is called "images". Currently the page is configured to load the thumbnail of the image. Any help would be much appreciated. :0) Perch
|
|
|  |
 |

Dave
Staff
/ Moderator

Jul 1, 2008, 11:06 PM
Post #2 of 18
(1091 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Perch, Do you need any information from the record or just the image? I have two ideas in mind. 1) You could just load 10 records (sorted randomly), display them in a loop and stop after we hit the first image. We'd have to count on the fact that one of those 10 records had images defined though. 2) All the uploads are stored in a separate table called 'uploads'. We could query that table directly for a random upload for the table and field. If you could let me know the name of your table and upload field I can write up some code. Hope that helps! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

Perchpole
User
Jul 2, 2008, 8:06 AM
Post #3 of 18
(1084 views)
Shortcut
|
|
Re: [Dave] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi, Dave - Given a choice I suspect I'd prefer the second option. The tablename is: products_classic The upload field is: images Thanks, :o) Perch
|
|
|  |
 |

Jake
Staff
/ Moderator

Jul 2, 2008, 1:36 PM
Post #4 of 18
(1073 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Perch, Thanks for your reply! Here's the code you'll want to use for this:
<?php list($uploadRecords, $uploadMetaData) = getRecords(array( 'tableName' => 'uploads', 'limit' => '1', 'orderBy' => 'RAND()', 'where' => 'tableName = "classic" && fieldName = "images"', )); ?> <?php foreach ($uploadRecords as $record): ?> <?php echo $record['urlPath'] ?> <?php endforeach ?> All that code does is randomly return the URL for one image upload in your database. If this doesn't work out for you, drop me an email at jake@interactivetools.com with your FTP information so I can take a look at the code being used on this page directly. Keep us updated with how this is working out. ----------------------------------------------------------- Cheers, Jake Swanson - Product Specialist support@interactivetools.com
Hire me! Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.
|
|
|  |
 |

Perchpole
User
Jul 2, 2008, 3:50 PM
Post #5 of 18
(1071 views)
Shortcut
|
|
Re: [Jake] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi, Jake - Thanks for the code. I've just tested it on one of my newer CMSB sites and it works perfectly. However, as I mentioned in my original, the site that I revisiting with this image rotator is an older CMSB installation which uses the old code format. As a result, your code (in its current format) does not work. I've tried to adapt it, purely by following my nose, and this is the result: <?php require_once "web/viewer_functions.php"; $options = array(); $options['tableName'] = 'uploads'; $options['titleField'] = ''; $options['viewerUrl'] = '/classic/products_classicPage.php'; $options['orderBy'] = 'RAND()'; $options['pageNum'] = ''; $options['perPage'] = '1'; $options['where'] = 'tableName = "products_classic" && fieldName = "images"'; $options['useSeoUrls'] = ''; list($uploadRecords, $uploadMetaData) = getRecords($options); ?> Unfortunately, it doesn't seem to work. All I get is an error message indicating a "Call to undefined function: getrecords()... " in the line hi-lighted in red above. Any tips? :0) Perch
|
|
|  |
 |

Jake
Staff
/ Moderator

Jul 2, 2008, 6:19 PM
Post #6 of 18
(1068 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Perch, Sorry about that! Try this code instead:
<?php require_once "web/viewer_functions.php"; $options = array(); $options['tableName'] = 'uploads'; $options['titleField'] = ''; $options['viewerUrl'] = '/classic/products_classicPage.php'; $options['orderBy'] = 'RAND()'; $options['pageNum'] = ''; $options['perPage'] = '1'; $options['where'] = 'tableName = "products_classic" && fieldName = "images"'; $options['useSeoUrls'] = ''; list($uploadRecords, $uploadMetaData) = getListRows($options); ?> <?php foreach ($uploadRecords as $record): ?> <?php echo $record['urlPath'] ?> <?php endforeach ?> Let us know if that does the trick. ----------------------------------------------------------- Cheers, Jake Swanson - Product Specialist support@interactivetools.com
Hire me! Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.
|
|
|  |
 |

Perchpole
User
Jul 3, 2008, 2:43 AM
Post #7 of 18
(1033 views)
Shortcut
|
|
Re: [Jake] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Jake - Excellent. Once again it works perfectly. Now, taking things on a step - towards their natural conclusion...! Is there any way I can pull more details from the upload's main data? In a perfect world what you'd want is the ['title'] of the record to appear below the upload which also acts as a ['_link'] to the page viewer. So, the visitor is presented with a random image under which appears the title of the item. The visitor then clicks on the title to view the full page of information. Can you see where I'm going with this? Is it do-able? :0) Perch
|
|
|  |
 |

Jake
Staff
/ Moderator

Jul 3, 2008, 1:31 PM
Post #8 of 18
(994 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Perch, What title were you looking to retrieve here? The title for the image, or the title for its associated record? You can pull the image's title by using this code in the foreach loop: <?php echo $record['info1'] ?> You can also use this to generate the link to the record's detail page (not the image): <?php echo $record['_link'] ?> Let me know if you wanted to use the other title and I'll spend some more time looking into that, as it could get a bit tricky! ----------------------------------------------------------- Cheers, Jake Swanson - Product Specialist support@interactivetools.com
Hire me! Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.
|
|
|  |
 |

Perchpole
User
Jul 3, 2008, 3:39 PM
Post #9 of 18
(991 views)
Shortcut
|
|
Re: [Jake] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi, Jake - That works fine. However, if you're up for a challenge, I'd still like to see if you could think your way around my earlier post - regarding the use of the other data associated with the image/upload. Most records have ['title'] and ['content'] fields and I thought it might be useful to learn if there was a way to show this information beneath the images called by the rotation code. Being able to show the ['title'] of the record would be particularly helpful. I appreciate I could use the ['info1'] code - but this doesn't always tell the full story! Just a thought. :0) Perchpole
|
|
|  |
 |

Dave
Staff
/ Moderator

Jul 4, 2008, 11:24 AM
Post #10 of 18
(971 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Perch, We're getting pretty advanced here, and it requires a few queries to get all the data, but one way is to use a viewer to load the record based on the record number that is attached to the upload:
<?php require_once "web/viewer_functions.php"; // load upload $options = array(); $options['tableName'] = 'uploads'; $options['titleField'] = ''; $options['viewerUrl'] = '/classic/products_classicPage.php'; $options['orderBy'] = 'RAND()'; $options['pageNum'] = '1'; $options['perPage'] = '1'; $options['where'] = 'tableName = "products_classic" && fieldName = "images"'; $options['useSeoUrls'] = ''; list($uploadRecords, $uploadMetaData) = getListRows($options); $upload = @$uploadRecords[0]; // get first upload // load record $recordNum = @$upload['recordNum']; $options = array(); $options['tableName'] = 'products_classic'; $options['titleField'] = ''; $options['viewerUrl'] = '/classic/products_classicPage.php'; $options['pageNum'] = '1'; $options['perPage'] = '1'; $options['where'] = "num = '$recordNum'"; $options['useSeoUrls'] = ''; list($productRecords, $productMetaData) = getListRows($options); $product = @$productRecords[0]; // get first product ?> Then you should have your upload in $upload and the record it came from in $record. Note, I wrote this code in the forum, it should be fine but may require some tweaks. Let me know if you have any problems with it. Hope that helps! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

Perchpole
User
Jul 5, 2008, 5:55 AM
Post #11 of 18
(961 views)
Shortcut
|
|
Re: [Dave] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
DAve - Amazing. You've cracked it yet again! This is the code I'm using to display the the uploads and associated data: <?php foreach ($uploadRecords as $record): ?> <a href="<?php echo $product['_link'] ?>"><IMG SRC="<?php echo $record['thumbUrlPath'] ?>" /> <BR /> <?php echo $product['title'] ?></a> <?php endforeach ?> The only thing you need to remember is to put the right placeholders in the right places - otherwise things get a bit muddled! Just one final request on this topic: could you conjure-up a version of your code using the modern CMSB format, please? :0) Perch
|
|
|  |
 |

Dave
Staff
/ Moderator

Jul 7, 2008, 12:18 AM
Post #12 of 18
(924 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Perch, here's the code in modern format. Note that I don't have all your sections setup locally so this is untested.
// load upload list($uploadRecords, $uploadMetaData) = getRecords(array( 'tableName' => 'uploads', 'where' => 'tableName = "products_classic" && fieldName = "images"', 'orderBy' => 'RAND()', 'limit' => '1', )); $upload = @$uploadRecords[0]; // get first record // load record $recordNum = @$upload['recordNum']; list($productRecords, $productMetaData) = getRecords(array( 'tableName' => 'products_classic', 'where' => "num = '$recordNum'", 'limit' => '1', )); $product = @$productRecords[0]; // get first record Let me know how it goes! :) Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

Perchpole
User
Jul 8, 2008, 5:45 PM
Post #13 of 18
(900 views)
Shortcut
|
|
Re: [Dave] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi, Dave (and Jake) - Thanks for your help with this matter. I've used both versions of the code to create random image pages - and both work very well. However, there is one small issue which is rather interesting... The code works by pulling images from the Uploads table. Trouble is, this includes images which belong to records that have been deleted! I checked the Upload table via phpmyadmin and, sure enough, all the images I've uploaded are still present. As a work around I've added some more code to the Uploads' "where" condition - which seems to do the trick. It's not really an issue but it is interesting to learn that the Uploads stay around even when the records associated with them have been erased! Thanks, again, for your help. :0) Perch
|
|
|  |
 |

Dave
Staff
/ Moderator

Jul 8, 2008, 5:49 PM
Post #14 of 18
(899 views)
Shortcut
|
|
Re: [Perchpole] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi perch, Thanks for reporting that. Uploads should be erased with records in all cases. I'll do some tests on that locally and fix it for the next version if needed. Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

jposwald
User
Oct 22, 2008, 9:22 AM
Post #15 of 18
(318 views)
Shortcut
|
|
Re: [Dave] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
I have this:
<?php /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */ require_once "/home/content/d/e/r/derekseal/html/utahreoexperts/cmsAdmin/lib/viewer_functions.php"; // load upload list($uploadRecords, $uploadMetaData) = getRecords(array( 'tableName' => 'uploads', 'where' => 'tableName = "videos" && fieldName = "video"', 'orderBy' => 'RAND()', 'limit' => '1', )); $upload = @$uploadRecords[0]; // get first record // load record $recordNum = @$upload['recordNum']; list($videosRecords, $videosMetaData) = getRecords(array( 'tableName' => 'videos', 'where' => "num = '$recordNum'", 'limit' => '1', )); $videos = @$videosRecords[0]; // get first record ?> And then I put variables to list as: <?php echo $videosRecord['title'] ?> <?php echo $videosRecord['description'] ?> But it seems to take me the uploads but no the videosRecord, as you can see in: http://www.utahreoexperts.com/selling-your-home/videos-about-selling-a-home/video/?Video-1-Selling.-3 Please help with this one. Cheers, Juan.
|
|
|  |
 |

Dave
Staff
/ Moderator

Oct 22, 2008, 11:58 AM
Post #16 of 18
(306 views)
Shortcut
|
|
Re: [jposwald] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Hi Juan, A quick question first - what version of CMS Builder are you running? Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

jposwald
User
Oct 22, 2008, 12:48 PM
Post #17 of 18
(302 views)
Shortcut
|
|
Re: [Dave] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Dave, I'm running 1.22 version.
|
|
|  |
 |

Dave
Staff
/ Moderator

Oct 23, 2008, 2:46 PM
Post #18 of 18
(276 views)
Shortcut
|
|
Re: [jposwald] 'Where' to find an answer!
[In reply to]
|
Can't Post
|
|
Try this: <?php echo $videos['title'] ?> <?php echo $videos['description'] ?> Let me know if that fixes it. Dave Edis - Senior Developer interactivetools.com
|
|
|  |
|