Ortix Posted August 18, 2009 Share Posted August 18, 2009 Hello everyone! I'm at the brink of going mad right now! So let me start: I'm making a website with files that have multiple mirrors. Some have 5, some have 3. To make this happen i use joomla and K2 CCK as my tools of trade. I made some extra fields in K2, which are empty download link fields. These fields belong to a group. When i assign the group to a category these fields automatically appear with every single item in that specific category. Now please focus on the coming php and not on the groups and what not. I tried every possible option without success. This is the easiest way around (Which i'm gonna describe now) Basically, I have 8 or so extra fields. They are all links. Some items use 5 of them and some use 3. That leaves me with a lot of empty fields that DO show up in the item. Example There is one download link that has a value and the other one that does NOT. I want to be able to hide the download links that have no values or equal a value like empty or something. Also, in the admin back-end the "value" i'm talking of consists of 3 parts. The text, the address, and the function (open in new window etc). So how do i hide the field which renders nothing for the value so that i only see fields that have actual links in them. This is the code that renders the fields (original): <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <h3><?php echo JText::_('Download Links'); ?></h3> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <br class="clr" /> </li> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> I tried some mods without success. Either an error comes up, ALL the fields disappear or they all stay. Currently i have something like this: <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <h3><?php echo JText::_('Download Links'); ?></h3> <ul> <?php #var_dump($this->item->extra_fields); ?> <?php foreach ($this->item->extra_fields as $key => $extraField) { $value = trim($extraField->value); if (is_null($value)) { continue; } ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <br class="clr" /> </li> <?php } ; ?> I am a total php noob. I got some help without success. Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/ Share on other sites More sharing options...
deansatch Posted August 18, 2009 Share Posted August 18, 2009 I struggle a bit with classes and OOP but if I understand correctly, you should only build the array with the ones that have a value. Otherwise something like this? <?php if($extraField->value !=''){ ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <br class="clr" /> </li> <?php } ?> Probably wrong but I am still doing old school php Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-900952 Share on other sites More sharing options...
ignace Posted August 18, 2009 Share Posted August 18, 2009 Please post all relevant code including queries etc.. Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901082 Share on other sites More sharing options...
Ortix Posted August 18, 2009 Author Share Posted August 18, 2009 what do you mean with relevant code? Sorry, i'm very noob at php. I haven't had the time to study it yet. I'm trying to learn by myself. And what do you mean with queries as well. Please don't hate. If you tell me what to do, i will do it! As for the relevant code, that is A LOT. There are files scattered all over and posting that would be a pain both for you and me. Unless you want me to post the file this code snippet belongs to. As for queries, do you mean var_dump? Sorry for my noobish ness. Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901208 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 queries as in mysql or other database queries I would presume. What errors come up? Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901231 Share on other sites More sharing options...
ignace Posted August 18, 2009 Share Posted August 18, 2009 what do you mean with relevant code? Sorry, i'm very noob at php. I haven't had the time to study it yet. I'm trying to learn by myself. And what do you mean with queries as well. Please don't hate. If you tell me what to do, i will do it! As for the relevant code, that is A LOT. There are files scattered all over and posting that would be a pain both for you and me. Unless you want me to post the file this code snippet belongs to. As for queries, do you mean var_dump? Sorry for my noobish ness. You don't need to apologise if you don't understand some of the terminology. Just ask and we will clarify or if you <3 Google like I do, you can prefix whatever you don't understand with 'define:' like: http://www.google.com/search?q=define%3Aterminology Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901259 Share on other sites More sharing options...
Ortix Posted August 18, 2009 Author Share Posted August 18, 2009 these are just errors like unexptected endif or endforeach. What i DID find out however is if i do this (or anything else that states value is empty): <?php foreach ($this->item->extra_fields as $key=>$extraField) if(empty($extraField->value)); else{ ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> <br class="clr" /> </li> <?php } ?> there is an extra field that indeed does NOT show up if it's empty. And that field ONLY has 1 value to enter. It's a simple text box. The extra field i am using (links) has 3 parameters which are: name, link, function (open in new window etc). This code does not affect those! Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901353 Share on other sites More sharing options...
Ortix Posted August 18, 2009 Author Share Posted August 18, 2009 Sorry for double post but for some reason i can't edit my old post. i also found this: elseif ($extraFieldType=='link'){ if (substr($values[$i], 0, 7) == 'http://'){$values[$i] = $values[$i];} else {$values[$i] = 'http://'.$values[$i];} $object->set('value', $values[$i]); } This is a system file for k2. The code snippet in the previous posts is not in the same file as this one Quote Link to comment https://forums.phpfreaks.com/topic/170830-hide-field-if-value-is-emptynullequal-to-something/#findComment-901377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.