Sigh... I know it should be easy... Help.. Please.

8 posts by 2 authors in: Forums > CMS Builder
Last Post: January 26, 2008   (RSS)

By BigBear - January 23, 2008

Hi Dave,

I have finally thrown my hat down in frustration.. lol. I need help. I know NOTHING about php and mySql, but I will be danged if I dont learn! Ok. Here is what I want to do. I have a database with business names etc etc. and with an upload field for a banner, and a couple check boxes for "categorizing" the businesses.

Here is what I would like to do. I would like to make a viewer that will show only the banner of a Randomly chosen Company, in a specified location. I have a field in my database called "c_of_c". If this is checked I would like the program to display that banner on whatever page I set the viewer into. So basically the script must first choose a company, then check to make sure if the "c_of_c" is checked.. if yes, then show banner... or content.

Thanks alot for your help!

I am absolutely ecstatic about the potential of this utility... just need to learn how to speak the language.

Rob Parker

website is at: http://www.alexandria-ontario.net/clientList.php

PS: Can you suggest some real SIMPLE BASIC php and mySql literature that would help me?

Re: [BigBear] Sigh... I know it should be easy... Help.. Please.

By Dave - January 23, 2008

Hi BigBear,

Don't worry, you don't need to know PHP and MySql unless you want to do really advanced stuff.

Let's try this one step at a time. First, to get random results you can set the orderBy field to RAND() like this:

$options['orderBy'] = 'RAND()';

Next, you want to display only banners with c_of_c checked? You use the where option to filter like this:

$options['where'] = 'c_of_c = "1"';

And then the company name, how do you want that passed to the page? Your example link isn't working anymore.

PS: To learn basic PHP and MySQL just google "Learn PHP" and "Learn Mysql"

Hope that helps! Let me know!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Sigh... I know it should be easy... Help.. Please.

By BigBear - January 23, 2008 - edited: January 23, 2008

Hi Dave,

here is what I have - with your additions... I still get an error though.

<?php require_once "/home/bigbearcreations/alexandria-ontario.net/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['orderBy'] = 'RAND()';
$options['tableName'] = 'clients'; // (REQUIRED) MySQL tablename to list record from. Example: "article";
$options['recordNum'] = ''; // (optional) Record number to display. Example: "1"; Defaults to number on end of url, then 1
$options['where'] = 'c_of_c = "1"';
$record = getRecord($options);
?>

This is what I use to put the uploaded banner on the page. I know its something I am doing wrong.. but I can't figure out any other options.

<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" />

This is the error that I am getting at the bottom of the page where I want the uploaded banner displayed

Page Viewer (clients) errors
Unknown option 'orderBy' specified. Valid option names are: (tableName, recordNum, where)


One method I did use was to paste the banner in a WYSIWYG window and then display that... But I would rather have the client upload his actual banner and just be able to paste that code where I need it.

Sorry about the link problem: here is the proper link: http://www.alexandria-ontario.net/clientsPage.php The banner should show up on any of the clientspage creations. If I did another typo, just select the business directory from any of the menus.

Thanks for your help.

Rob

Re: [BigBear] Sigh... I know it should be easy... Help.. Please.

By Dave - January 23, 2008

No worries, we want to start with a "List Viewer" for this one, not a "Page Viewer".

Try creating a list viewer, then adding those options, and also setting 'pageNum' and 'perPage' to 1 (so it always shows the first result and only 1 result).

If you get an error still, attach the php file to this thread and I'll have a look at it for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Sigh... I know it should be easy... Help.. Please.

By BigBear - January 25, 2008

Hi Dave,

I upgraded to the latest version, no problems with the upgrade, but I am still having problems with getting a random uploaded banner to display.

I made all the changes you suggested above, and made a list viewer. Now I don't get any image. I get no error, but I get no image. I set the condition to bp=1 (I changed the field to Banner Program). There are only 4 records with banners at the moment, but none are being displayed.

I have attached the php file as requested.

Thanks Much!
Attachments:

clientspage.php 10K

Re: [BigBear] Sigh... I know it should be easy... Help.. Please.

By Dave - January 26, 2008

Hi BigBear,

Try replacing this line


<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" /></th>

with this:

<?php foreach ($listRows as $record): ?>
<?php if ($record): ?>
<?php foreach (getUploads($options['tableName'], 'uploads', $record['num']) as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" /></th>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>


That's the extra bit of code that loops over each matching record (just 1 in this case) and then loops over each upload for that 1 record.

If that's does work and you want me to login and take a look just email me ftp details at dave@interactivetools.com

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Sigh... I know it should be easy... Help.. Please.

By BigBear - January 26, 2008

Hi again.

I made the changes you gave me, and it still does not want to display an uploaded picture... so here is what I did. Instead of the field being an upload file, I changed the field to a WYSIWYG type. I then insert the banner as an image. Instead of displaying the downloaded file record, I now ask it to show the WYSIWG content, and no problems. Wierd.

I have encountered one problem with this though - I cannot link the banner to a url through the editor - it gives me an "error on page" and will not save it properly. Can I just wrap an ahref tag with the hompage_url field to direct it?

Thanks again Dave!

The service level here has been absolutely incredible! Canadian Companies ROCK!!!

Re: [BigBear] Sigh... I know it should be easy... Help.. Please.

By Dave - January 26, 2008

Thanks for the praise! :)

Yes, you should be able to wrap an href around it and have it work. Give it a try.

And if you want us to hunt down what was going wrong with the other method we can do that too.
Dave Edis - Senior Developer
interactivetools.com