Jump to content

Recommended Posts

Hey,

 

I'm trying to display 7 columns and then stack the rest under each other so that it doesn't run off the page.

 

echo '<table width="400" border="0" cellspacing="0" cellpadding="0">';
		echo '<tr><td>'.CLOSE_OUT_MESSAGE.'</td></tr>';
		echo '</table>';
		echo '<table width="800" border="0" cellspacing="0" cellpadding="0">';
      while($row = db_fetch_array($letterQuery))
      {
        $tempLetter = explode(" ", $row['products_description']);
        if(!in_array($tempLetter[0], $used))
        {
          $used[] = $tempLetter[0];
          echo '<tr>';
          for ($i = 0; $i < 7; $i++)
            echo '<td><a href="'.link_url(PAGENAME_FEATURES, 'featI4yrDauy=4&letter=' . $tempLetter[0]).'" >'.$tempLetter[0].'</a></td>';
          echo '</tr>';
        }
      }
      echo '</table>';

 

I've tried using a for loop to hit 7 and go down, but it repeats EVERYTHING 7 times.

 

Help please? :)

echo '</pre>
<table width="400" border="0" cellspacing="0" cellpadding="0">';
echo ''.CLOSE_OUT_MESSAGE.'';
echo '</table>';<br>echo '<table width="800" border="0" cellspacing="0" cellpadding="0">';
      $rowcnt = 0;
      while($row = db_fetch_array($letterQuery)) 
      {
       
        $tempLetter = explode(" ", $row['products_description']);
        if(!in_array($tempLetter[0], $used))
        {
          $rowcnt++;
          $used[] = $tempLetter[0];
          if ($rowcnt             echo '';
            echo ''.$tempLetter[0].'';
            echo '';
          } else {
            // Do your stacking stuff here
          }
        }
      }
      echo '</table>

hmm..

 

That seems to do some-what of what I'm looking for. It displays the first 7, which is fine, but I if, for example, I have 14 in total, the next 7 would need to display under that.

 

I've tried a couple of different solution but I haven't gotten the solution I'm looking for :-\

echo '<table width="400" border="0" cellspacing="0" cellpadding="0">';
echo '<tr><td>'.CLOSE_OUT_MESSAGE.'</td></tr>';
echo '</table>';
echo '<table width="800" border="0" cellspacing="0" cellpadding="0"><tr>';
      $rowcnt = 0;
      while($row = db_fetch_array($letterQuery)) 
      {
       
        $tempLetter = explode(" ", $row['products_description']);
        if(!in_array($tempLetter[0], $used))
        {
          $rowcnt++;
          $used[] = $tempLetter[0];
            echo '<td><a href="'.link_url(PAGENAME_FEATURES, 'featI4yrDauy=4&letter=' . $tempLetter[0]).'" >'.$tempLetter[0].'</a></td>';
          if ($rowcnt%7==0) echo "</tr><tr>";
        }
      }
      echo '</tr></table>';

That works perfect. But I'm confused by this concept, maybe I'm over complicating it (like always).

 

If the remainder is '0' close the table row and open a new table row.

 

Once you open the new table row, theres no value/variable within the new table row.... This is where I get confused.

I don't understand what you're asking... somewhere earlier in your script you query your database for info.  Then you have this loop that goes through each row returned from your query. So you want those rows to be displayed in an html table 7 columns wide and however many rows tall that works out to, right?

 

Well the normal structure of an html table is:

<table>
  <tr>
    <td></td>
  </tr>
</table>

 

So before your loop, you echo out the opening table tag and the first opening row tag.  Then for your loop, for each iteration, you just echo the data out with td tags wrapped around it.  So you want to make a new row every 7 times, so you have a variable incrementing every iteration.  Use a modulus condition to see if we're on a 7th iteration. If we are, close out the row and open a new one.  After the loop ends, put the final row's closing tag and the table's closing tag.

 

Was there something in there you don't understand, or am I not understanding your problem/goal?

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.