Jump to content

What's wrong with the following table


NAmeviolated

Recommended Posts

 

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; ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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++; ?>

Link to comment
Share on other sites

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; ?>
    

Link to comment
Share on other sites

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";
}

?>

Link to comment
Share on other sites

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 {}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.