NAmeviolated Posted October 25, 2011 Share Posted October 25, 2011 I can get the first column to display but the second column isn't showing up. <?php $table = '<table width="400px" border="0">'; ?> <?php $counter = 0; ?> <?php $total1 = count($this->item->extra_fields); ?> <span class="catItemExtraFieldsLabel"><?php echo $total1 ; ?></span> <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField) : ?> <?php if ($counter%2 == 0) : ?> <?php if($extraField->value) : ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if ($counter%2 == 0) : ?> <?php '<tr><td>' ; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <span class="catItemExtraFieldsLabel"><?php echo $counter ; ?></span> <?php '</td>'; ?> <?php else: ?> // second column <?php '<td>'; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <span class="catItemExtraFieldsLabel"><?php echo $counter ; ?></span> <?php '</td></tr>' ; ?> <?php endif ?> <?php $counter++; ?> </li> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> <?php $table .= '</table>'; ?> <?php echo $table; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 I would try to help, but that is some god awful code you have there. It would take me 5-10 minutes just to deconstruct it to try and understand. I assume you are using DreamWeaver or some other WYSIWYG editor. Get yourself a decent code editor (even Notepad ++ would be a good choice). Anyway, if you want to put your coed in [ CODE ] tags as you are supposed to, I *might* be included to help. Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Everything works, except the construction of the table, thinking I'm missing something in between the following code. <?php if ($counter%2 = 0) : ?> <?php '<tr><td >' ; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php '</td>'; ?> <?php else: ?> // second column <?php '<td >'; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php '</td></tr>' ; ?> <?php endif ?> <?php $counter++; ?> Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Definately something wrong with the first column, if I do a ($counter%2 != 0) it works for the else statement <?php $table = '<table width="400px" border="0">'; ?> <?php $counter = 0; ?> <?php $total1 = count($this->item->extra_fields); ?> <span class="catItemExtraFieldsLabel"><?php echo $total1 ; ?></span> <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField) : ?> <?php if ($counter%2 == 0) : ?> <?php if($extraField->value) : ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if ($counter%2 = 0) : ?> <?php '<tr><td width ="200">' ; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php '</td>'; ?> <?php else: ?> // second column <?php '<td width = "200">'; ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php '</td></tr>' ; ?> <?php endif ?> <?php $counter++; ?> </li> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> <?php $table .= '</table>'; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 As I stated the code is a mess. Putting all those beginning and ending PHP tags on every line makes the code unreadable and unwieldy. After deconstructing all of it I can see you have a ton of invalid HTML content. You have opening/closing tags that do not match up and there are tags that are simply out of place (e.g. <li> tags around table rows. I have rebuilt the entire script in a more logical, readable format that may work for you. <?php $columns = 2; $total1 = count($this->item->extra_fields); echo "<span class='catItemExtraFieldsLabel'>{$total1}</span>\n"; if($this->item->params->get('catItemExtraFields') && $total1) { $addlInfo = JText::_('K2_ADDITIONAL_INFO'); $counter = 0; //begin page output echo "<!-- Item extra fields -->\n"; echo "<div class='catItemExtraFields'>\n"; echo "<h4>{$addlInfo}</h4>\n"; echo "<table width='400px' border='0'>\n"; foreach ($this->item->extra_fields as $key=>$extraField) { if($extraField->value) { $counter++; //open new row if ($counter%$columns == 1) { echo "<tr>\n"; } //Prepare data for current record $oddEven = ($key%2) ? "odd" : "even"; $type = ucfirst($extraField->type); $class = "{$oddEven}type{$type}group{$extraField->group}"; //Display current record echo "<td class='{$class}'>\n"; echo "<span class='catItemExtraFieldsLabel'>{$extraField->name}</span>\n"; echo "<span class='catItemExtraFieldsValue'>{$extraField->value}</span>\n"; echo "<span class='catItemExtraFieldsLabel'>{$counter}</span>\n"; echo "</td>\n"; //Close completed row if ($counter%$columns == 0) { echo "</tr>\n"; } } //Close last row if not already closed if($counter%$columns != 0) { echo "</tr>\n"; } } //Close table echo "</table>\n"; echo "<div class='clr'></div>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Sorry, the code is Joomla/K2 and it's the way they have set it up, I've just been modifying it, to display a table. Thanks for your help, will try it out. Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 hmmm, looking at it, it should be working, but still displays it as a list. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 Don't know what to tell you, there is no "list" code in there. But, perhaps it has something to do with the classes you are using. Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Think your right here is the css, gathering I take out the list from here div.catItemExtraFields, div.genericItemExtraFields {margin:16px 0 0 0;padding:8px 0 0 0;border-top:1px dotted #ddd;} div.catItemExtraFields h4, div.genericItemExtraFields h4 {margin:0;padding:0 0 8px 0;line-height:normal !important;} div.catItemExtraFields ul, div.genericItemExtraFields ul {margin:0;padding:0;list-style:none;} div.catItemExtraFields ul li, div.genericItemExtraFields ul li {display:block;} div.catItemExtraFields span.catItemDateCreated {} div.catItemExtraFields ul li span.catItemExtraFieldsLabel, div.genericItemExtraFields ul li span.genericItemExtraFieldsLabel {display:block;float:left;font-weight:bold;margin:0 4px 0 0;width:30%;} div.catItemExtraFields ul li span.catItemExtraFieldsValue {} Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 I don't understand it, if I put echo "<span class='catItemExtraFieldsLabel'>{$counter}</span>\n"; above the line with echo "<td class='{$class}'>\n"; the output is 12 but below that line the output is 1 2 Not being that strong in coding I can't see any reason for it. Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Semi worked it out. The logic for the final If statement to close the final row was causing issues, once I commented it out, it displayed the columns. Trying to check the logic now with a pen and paper Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 Ah, yes. That block to close the last row (if needed) should go after the foreach() loop. Right before this comment //Close table Quote Link to comment Share on other sites More sharing options...
NAmeviolated Posted October 25, 2011 Author Share Posted October 25, 2011 Ok Cool. Thanks heaps for the help . One other weird thing, the span classes aren't correctly formatting the data. Will look at it tomorrow, getting so so sick of Joomla, can't wait to finish this site and go back to Wordpress. Quote Link to comment 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.