line problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sc0rp
Forum Newbie
Posts: 3
Joined: Tue Jan 14, 2003 8:29 am
Location: Belgium

line problem

Post by Sc0rp »

well Im trying to make this gallery work on my site so I tried this php script called php image gallery.. now I know there are a lot better ones but I just want a simple one that I can improve myself..

so I started editing it so I only had the thumb addon.. and so I could put it inside my own table inside of my own site..

thing is.. when I use the original code it creates a new table under my own tables.. I dont want that of course so I edited it a bit.. now it shows the thumbs and all works fine BUT.. it doesnt go to the next line after x pictures have been shown.. so if there are 20 pictures in a gallery they are all shown horizontally on one line! and this only happens when I use my edited code..

so please take a look and see whats wrong!

Original Code:

Code: Select all

<tr> 
     <td bgcolor=#F4F4F4> 
       <table width=100% border=0 cellspacing=0 cellpadding=0> 
         <tr> 
          <td><table width=100%><tr>"; 
 
      $counter = 0; 
      $rowcount = 0; 
      foreach ($file_array as $file) { 
 
        if ($counter == 0 or $counter == $horizontalpics) $counter=1 ; 
        if ($counter == 1) { 
          if ($rowcount ==0 or $rowcount == 4) { 
            echo "</tr></table><table width=100%><tr> 
                      <td><hr> 
                      <div align=center>[<a href=$linkhome>Back to the gallery index</a>] - [<a href=#top>Back 
                     to the top</a>]</div><hr> 
                      </td></tr><table width=100%>"; 
               $rowcount = 1; 
                $counter=1; 
              } 
         echo "</tr><tr>"; 
          ++$rowcount; 
        } 
 
 
        ++$counter; 
        $my_link = $linkname.$file; 
        $my_thumb = $thumbname.$file; 
        echo "<td><div align=center><a href=$my_link target=gallerie><img src=$my_thumb alt=$file border=0></a></div></td>"; 
      } 
     } 
 
           echo "</tr></table></td> 
         </tr> 
       </table> 
    </td> 
  </tr>

Edited Code:

Code: Select all

<tr>
  <td width=8 height=692 rowspan=2>

  &nbsp;</td>
  <td width=830 height=677>"; 
	 $counter = 0;
	 $rowcount = 0;
 	 foreach ($file_array as $file) {

 	   if ($counter == 0 or $counter == $horizontalpics) $counter=1 ;
 	   if ($counter == 1) {
 	     if ($rowcount ==0 or $rowcount == 4) {
 	       echo "<table width=100%>";
               $rowcount = 1;
               $counter=1;
             }
 	     ++$rowcount;
 	   }


 	   ++$counter;
 	   $my_link = $linkname.$file;
 	   $my_thumb = $thumbname.$file;
 	   echo "<td><a href=$my_link target=gallerie><img src=$my_thumb alt=$file border=0></a></td>";
 	 }
 	 }

          echo "</tr></table>
</td>



  <td width=16 height=677>

</td>
</tr>
I left out a whole bunch but this is only for displaying the thumbs.. and this is where it goes wrong.. please help!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

oh oh, take a look at the source as seen from the browser (view->page source on IE) for both versions and you'll find that your changes messed with the table-structure.

Code: Select all

<table> <!-- begin table -->
	<tr> 					<!-- new row in a table -->
		<td>A</td> 	 	 	<!-- a cell in that row -->
		<td>B</td> 	 	 	<!-- another cell in that row -->
	</tr>					<!-- row ends here -->
	<tr> 					<!-- new row in a table -->
		<td>C</td>  	 		<!-- a cell in that row -->
		<td>D</td>  	 		<!-- another cell in that row -->
	</tr>					<!-- row ends here -->
</table> <!-- end table -->
you may nest tables but you have to take care of the structure

Code: Select all

<table border="1">
	<tr>
		<td>
			<table>
				<tr>
					<td>A</td>
					<td>B</td>
				</tr>
				<tr>
					<td>C</td>
					<td>D</td>
				</tr>
			</table>
		</td>
		<td>
			<table>
				<tr>
					<td>a</td>
					<td>b</td>
				</tr>
				<tr>
					<td>c</td>
					<td>d</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table>
				<tr>
					<td>1</td>
					<td>2</td>
				</tr>
				<tr>
					<td>3</td>
					<td>4</td>
				</tr>
			</table>
		</td>
		<td>
			<table>
				<tr>
					<td>i</td>
					<td>ii</td>
				</tr>
				<tr>
					<td>iii</td>
					<td>iv</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
Post Reply