If then statement help

11 posts by 2 authors in: Forums > CMS Builder
Last Post: May 19, 2011   (RSS)

By dccreatives - May 16, 2011

How do I write my if then statement to show information only if there is a file uploaded.

<?php foreach ($downloadsRecord['bim_files'] as $upload): ?> <?php if ($upload): ?>
<li> <a href="http://www.axislighting.com/CMS/downloadsDetail-pop-bim.php?<?php echo $itemsRecord['download_id'] ?>" target="_blank" rel="gb_page_center[700, 480]">BIM Files</a></li><?php endif ?><?php endforeach ?>

This only doesn't show the upload. I want it to show if the field 'Bim_files' has an uploaded file uploaded to it. If not, leave empty.

Re: [dccreatives] If then statement help

By Jason - May 17, 2011

Hi,

Try this:

<?php if ($downloadsRecord['bim_files']): ?>
<li>
<a href="http://www.axislighting.com/CMS/downloadsDetail-pop-bim.php?<?php echo $itemsRecord['download_id'] ?>" target="_blank" rel="gb_page_center[700, 480]">BIM Files</a>
</li>
<?php endif ?>


This will only output a link if something has been uploaded to your bim_files field.

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: [Jason] If then statement help

By dccreatives - May 17, 2011

Thank You.

IT worked perfectly.

Now I need something a bit more advanced.

I need to say that if the $itemsRecord['download_id'] has an upload show code here....

How do I write this?

Re: [dccreatives] If then statement help

By Jason - May 17, 2011

Hi,

Do you mean something like this:

<?php if ($downloadsRecord['bim_files']): ?>
<?php if ($itemsRecord['download_id']): ?>
<li>
<a href="http://www.axislighting.com/CMS/downloadsDetail-pop-bim.php?<?php echo $itemsRecord['download_id'] ?>" target="_blank" rel="gb_page_center[700, 480]">BIM Files</a>
</li>
<?php endif ?>
<?php endif ?>


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: [Jason] If then statement help

By dccreatives - May 17, 2011

Let me explain further how I need more advanced cross-referencing:

Each itemDetail record has a download_id number to associate it to the downloads section. In the downloads section, I uploaded associated files to an item and I call it with in each itemDetail record via a link with the download_id reference.

On the itemsDetail page, I have a list of Downloads available hard-coded like this one:

<li> <a href="http://www.axislighting.com/CMS/downloadsDetail-pop-bim.php?<?php echo $itemsRecord['download_id'] ?>" target="_blank" rel="gb_page_center[700, 480]">BIM Files</a></li>

Now, I only want to show this <li> if the downloadsRecord 'bim_files' which is called from the itemsDetail page using this string $itemsRecord['download_id'] has an upload.

Here is my itemsDetail.php Page.

You can view the page here: http://www.axislighting.com/CMS/itemsDetail.php?9 (This page has no Bim Files), I do not want it to show the Bim Files List.

http://www.axislighting.com/CMS/itemsDetail.php?2 (This page does have Bim FIles and I want the link to show.)
Attachments:

itemsdetail_003.php 18K

Re: [dccreatives] If then statement help

By Jason - May 18, 2011

Hi,

Okay, I think I see what you're trying to do. The first problem I'm seeing with the page is all of your getRecords calls is using the "whereRecordNumInUrl()" function. That means if you're looking at item record 2, your retrieving the second record for all your other sections (distribution, brands, and downloads) as well. Chances are these records will not match up the way you want them to.

What is the name of the field in "downloads" that you associate with the "download_id" in "items"? In this example, we'll assume that you're using the "num" field in downloads to associate with the "download_id" field in items.

In that case, you would want to do your selection like this:

list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));

// show error message if no matching record is found
if (!$itemsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

$itemsRecord = $itemsRecords[0]; // get first record

list($downloadsRecords, $downloadsMetaData) = getRecords(array(
'tableName' => 'downloads',
'where' => "num = '".mysql_escape($itemsRecord['download_id'])."'",
'limit' => '1',
));

if ($downloadsRecord) {
$downloadsRecord = @$downloadsRecords[0]; // get first record
}
else {
$downloadsRecord = array();
}


This code means that downloadsRecord would only have a value if the download_id of the selected items record has a record in the downloads section. That way when deciding whether or not to display the downloads link is whether or not downloads['bim_files'] has a value:

<?php if (@$downloadsRecord['bim_files']): ?>
<li> <a href="http://www.axislighting.com/CMS/downloadsDetail-pop-bim.php?<?php echo $itemsRecord['download_id'] ?>" target="_blank" rel="gb_page_center[700, 480]">BIM Files</a></li>
<?php endif ?>


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: [Jason] If then statement help

By dccreatives - May 18, 2011 - edited: May 18, 2011

Looks like it works, but I am getting an error on top and it is throwing off the page a bit


http://axislighting.com/CMS/itemsDetail_nm_error.php?58


I noticed that it is never showing the Bim Files now, even when there is a file upload'

See this product. http://axislighting.com/CMS/itemsDetail_nm_error.php?1

There is a Bim FIle upload.
Attachments:

itemsdetail_nm_error.php 19K

Re: [dccreatives] If then statement help

By Jason - May 18, 2011

Hi,

ooops. There was a typo on the page, try changing this: (changes in red)


if ($downloadsRecords) {

$downloadsRecord = @$downloadsRecords[0]; // get first record
}
else {
$downloadsRecord = array();
}


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: [Jason] If then statement help

By dccreatives - May 19, 2011 - edited: May 19, 2011

Thank YOu. It worked perfectly.

Now I needed something similar, but not the same.

I have a page with all the downloads available for all brands.

http://www.axislighting.com/CMS/brandsList-downloads.php

Now I want to show only the files that are available. Some are available on the brand level. Like Brochure and Project Gallery. MEaning there is one per brand family.

But the IES, Bim and Spec Sheets are available on the item or product level. So I hard-coded the link like this:

<a href="downloadsList-ies_files.php?brand=<?php echo $record['name'] ?>" target="_blank" rel="gb_page_center[700, 480]"><img src="images/icon_ies.jpg" alt="" width="26" height="25" border="0" class="img-pad-top" /></a>

So it is calling the downloadList.php page specialized for the ies files and I integrated it to get the correct brand. So the page looks like this:

http://www.axislighting.com/CMS/downloadsList-ies_files.php?brand=dia

Now not all the brands have ies files uploaded. I do not want the link to show.

THe ies files are uploads in the downloadsRecords as 'ies_files'.

THe page is a brandsList page, so I need to include the downloadsRecord field 'ies files' so that the if then statement should work on this page to say if the downloadsREcord 'ies_files' has an upload show this:

<a href="downloadsList-ies_files.php?brand=<?php echo $record['name'] ?>" target="_blank" rel="gb_page_center[700, 480]"><img src="images/icon_ies.jpg" alt="" width="26" height="25" border="0" class="img-pad-top" /></a>

Thank You.
Attachments:

brandslist-downloads.php 11K