while loop with tables.

I need to use a while loop to display 5 tables like the one in the program. I am not sure how to do it. Each time the next table comes up I need to add 101px to the $top. Can someone please tell me if I even have the loop in the right spot. Any help would be greatly appreciated. I have everything that I added commented out. Thank You.
[php]
?php

echo “”;
echo “”;
echo “Find A Pet”;
echo ‘’;
echo ‘’;
echo ‘’;
echo ‘.auto-style1 {font-size: large;}’;
echo ‘.auto-style2 {font-size: large;text-align: right;}’;
echo ‘’;
echo ‘’;
echo ‘’;
/*$tops;
$HOFF = 101;
$tops = 24;
$tops + HOFF;
tops = $tops + “px”;
echo $tops;
exit;

while ($count = 0; $count <=5; $count = count + 1)
{
echo “&count = $count * 101 + $top”; */

echo ‘

’;
echo ‘’;
echo ‘’;
echo ‘
’;
echo ‘
’;
echo ‘
’;
echo ‘
’;
			echo '<table cellpadding="0" cellspacing="0" style="width: 100%; height: 78px">';
				echo '<tr><td class="auto-style1" style="width: 244px">Hoss</td><td class="auto-style1" style="width: 244px">';
				echo '&nbsp;</td><td class="auto-style2">BassetHound</td></tr>';
				echo '<tr><td class="auto-style1" colspan="2" style="width: 244">Male, 8 Weeks</td><td class="auto-style1">&nbsp;</td></tr>';
				echo '<tr><td class="auto-style1" colspan="2" style="width: 244">Gentry, Arkansas, 72734</td><td class="auto-style2">$600.00</td></tr>';
			echo '</table>';
		echo '</div>';
		
	echo '</tr>';

echo ‘

’;

echo ‘’;
echo ‘’;
?>

[/php]

you’re using for() syntax in the while() loop

while loop…
[php]
$count = 0;
while( $count <= 5 ) {
// code
$count++;
}
[/php]
for loop…
[php]
for( $count = 0; $count <= 5; $count++ ) {
// code
}
[/php]

try changing it to one or the other and let me know how it goes.

First of all I must say I don’t really agree with having absolute positioning and setting elements to be offset from the top like that.

This code makes absolutely no sense, it seems like a mix between javascript and php.
[php]$tops;
$HOFF = 101;
$tops = 24;
$tops + HOFF;
tops = $tops + “px”;
echo $tops;
exit;
while ($count = 0; $count <=5; $count = count + 1)
{
&count = $count * 101 + $top";[/php]

In your code you echo out all the html, making it a pain to handle later on. Depending on which editor you use you will have a hard time getting any code formatting or completion.

[hr]

Ok, enough ranting. Sorry if it came out harsh, I didn’t mean to be mean or anything ^^

[hr]

Compare this code, here I haven’t changed anything, I have only split the php and the html.
[php]<?php
// you can do php here!

// then we stop php execution and write normal html afterwards :smiley:
?>

Find A Pet .auto-style1 {font-size: large;} .auto-style2 {font-size: large;text-align: right;}
  /*$tops;
  $HOFF = 101;
  $tops = 24;
  $tops + HOFF;
  tops = $tops + "px";
  echo $tops;
  exit;
  while ($count = 0; $count <=5; $count = count + 1)
  {
  &count =  $count * 101 + $top"; */
  <table style="width: 100%" cellpadding="0" cellspacing="0">
     <tr>
     <img alt="" height="100" src="PuppyPannelFullTrans.gif" width="640"></td>
     <td>
        <div id="PetPanel_LayerPic_01" style="position: absolute; width: 120px; height: 83px; z-index: 1; left: 30px; top: 24px">
           <img alt="" height="79" src="../../petPicsThumbs/Hoss.jpg" width="96"></div>
        <div id="PetPanel_LayerText_01" style="position: absolute; width: 472px; height: 83px; z-index: 2; left: 156px; top: 24px">
           <table cellpadding="0" cellspacing="0" style="width: 100%; height: 78px">';
              <tr><td class="auto-style1" style="width: 244px">Hoss</td><td class="auto-style1" style="width: 244px">
                    &nbsp;</td><td class="auto-style2">BassetHound</td></tr>
              <tr><td class="auto-style1" colspan="2" style="width: 244">Male, 8 Weeks</td><td class="auto-style1">&nbsp;</td></tr>
              <tr><td class="auto-style1" colspan="2" style="width: 244">Gentry, Arkansas, 72734</td><td class="auto-style2">$600.00</td></tr>
           </table>
        </div>
        </tr>
  </table>
[/php]

It looks better in your IDE, I’ve attached a screenshot from netbeans.

I believe this is something along the lines of what you want
[php]<?php
// you can do php here!

// set first top position
$top = 24;

// set additional margin that will be added for each loop
$extraMargin = 101;

// then we stop php execution and write normal html afterwards :smiley:
?>

Find A Pet .auto-style1 {font-size: large;} .auto-style2 {font-size: large;text-align: right;}
  <?php for ($i = 0; $i < 6; $i++) { ?>
  <table style="width: 100%" cellpadding="0" cellspacing="0">
     <tr>
     <img alt="" height="100" src="PuppyPannelFullTrans.gif" width="640"></td>
     <td>
        <div id="PetPanel_LayerPic_01" style="position: absolute; width: 120px; height: 83px; z-index: 1; left: 30px; top: <?= $top + ($i * $extraMargin) ?>px">
           <img alt="" height="79" src="../../petPicsThumbs/Hoss.jpg" width="96"></div>
        <div id="PetPanel_LayerText_01" style="position: absolute; width: 472px; height: 83px; z-index: 2; left: 156px; top: <?= $top + ($i * $extraMargin) ?>px">
           <table cellpadding="0" cellspacing="0" style="width: 100%; height: 78px">';
              <tr><td class="auto-style1" style="width: 244px">Hoss</td><td class="auto-style1" style="width: 244px">
                    &nbsp;</td><td class="auto-style2">BassetHound</td></tr>
              <tr><td class="auto-style1" colspan="2" style="width: 244">Male, 8 Weeks</td><td class="auto-style1">&nbsp;</td></tr>
              <tr><td class="auto-style1" colspan="2" style="width: 244">Gentry, Arkansas, 72734</td><td class="auto-style2">$600.00</td></tr>
           </table>
        </div>
        </tr>
  </table>
  <?php } ?>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service