Jump to content


displaying data in rows of 7


8 replies to this topic

#1 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 13 November 2005 - 01:08 AM

Ok, I am working on a gallery thumbnail page displaying script. I have gotten most of the hard word done. Got it all the way to where I could even have it display a list of all the numbered thumbnails I need.

Now, my problem is this.
I want the images to be displayed in a horizontal rows of max 7 and max vertical rows of 4.

Something like this ( # = one image )
___________
|#|#|#|#|#|#|#|
|#|#|#|#|#|#|#|
|#|#|#|#|#|#|#|
|#|#|#|#|#|#|#|


Thats 28 images total. But it's also got to handle if there arn't 28 images to display. Something like this:


___________
|#|#|#|#|#|#|#|
|#|#|#|#|#|#|#|
|#|#|#|#|



Now, so far I have gotten these varibles made:
The number of horizontal rows, the number of images on the last horizontal row, the number of images in total on the page, the number of the first image out of all images, and the last number of the image on the page


Now, this is what I have so far:
<?php 
$galimg = 28;
$images = 76
$row = 7;

/* 
The important varibles:
Number of images per gallery = $galimg
The total number of set images = $images
The page number = $pg
The number of images per row = $row
The number of rows per page = $numrow
 */

$fsimg = ($pg - 1) * $galimg + 1;//first image

//total number of images on page
$onpage = $pg * $galimg;
$onpage = $images - $onpage;
$onpage = $onpage + $galimg;
if ($onpage > 28) {
	$onpage = 28;
	}


$laimg = $fsimg + ($onpage - 1);//Last image

//How many rows?
if ($onpage <= 7) { //One row
	$numrow = 1;
	} elseif  ($onpage <= 14) { //Two rows
	$numrow = 2;
	} elseif  ($onpage <= 21) { //Three rows
	$numrow = 3;
	} elseif  ($onpage <= 28) { //Four rows
	$numrow = 4;
	}

//how many images in the last row?
$lastrow = ($numrow * 7) - $onpage;
$lastrow = 7 - $lastrow;

//Make number of images array
$imagename = range($fsimg, $laimg);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gallery</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
echo "# of rows: $numrow <br>
# on last row: $lastrow <br>
# on page: $onpage <br>
Last img: $laimg <br>
First img: $fsimg <br>";
foreach ($imagename as $display) {
	echo "$display <br>";
	}
?>
<table align="center">
<tr><td colspan="7" class="eventheader">Pictures</td></tr>
<?php
//put displaying info here
?>
</table>
</body>
</html>
Now, each row that exsists this is the code I want:


<tr> //max 7 cells go here

And each cell is like this:
<td class="eventheader"><a href="image.php?num=$imagename"><img src="thumbs/$imagename.jpg" alt="Ninja" /></a></td>
With "$imagename" being replaced by the image name/number.

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 November 2005 - 02:11 AM

One thing that would help you explain your self is the fact that by "7 rows" you mean "7 columns" and "4 rows"... If you have problems remembering that, think greek (they loved columns).

Any who... Try something like this, since i don't feel like figuring out exactly which variable is which, you'll just have to improvise with what i'm giving you.
<table align="center">
<tr><td colspan="7" class="eventheader">Pictures</td></tr>
<?php
$y = 0;
for($x=0; $x < 28; $x++){
  // $total_images = the total number of images on the page
  if($x == $total_images){
    // Closes the row, ends the loop
    echo '</tr>';
    break;
  }

  if($y == 0){
    // Starts a new row
    echo '<tr>';
  }

  echo '<td class="eventheader"><a href="image.php?num='.$imagename.'"><img src="thumbs/'.$imagename.'.jpg" alt="Ninja" /></a></td>'."\n"; // \n is to help when viewing the html
  $y++; // Might need to move this a bit
  if($y == 6){
    // Ends the row, resets $y
    echo '</tr>';
    $y = 0;
  }
}
?>
</table>
</body>
</html>
The concept should get you going.

gl

#3 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 13 November 2005 - 03:13 AM

Ah yea. Forgot to put that seperate. I got it in the code but didn't post it out. Anyway, heres the varibles:

/*
The important varibles:
Number of images per gallery = $galimg
The total number of set images = $images
The page number = $pg
The number of images per row = $row
The number of rows per page = $numrow
*/

I'd look over what you gave and fix it up right now, but my eyes are shot and I'm hitting the sack. I'll put this on a "first come" thing.

lol

#4 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 13 November 2005 - 08:48 PM

Ok, I'm only double posting cause this is not working, and if I dont' double post, it won't come to attention.

It makes the cells as needed, many thanks for that, but instead of the number it should show in the file name and URL, instead it just says "Array"
You can view it here:
http://monkeysinabar.../index.php?pg=1
(havn't added on the forward and previous buttons, so if you want to view the other pages, just change pg=1 to pg=2 or pg=3 (thats as far as the number of images I got set to goes)

Anyway, heres all of the script, with what has been added on already by rc69

<?php 
$galimg = 28;
include("numimages.php");
$row = 7;
$numrow = 4;

/* 
The important varibles:
Number of images per gallery = $galimg
The total number of set images = $images
The page number = $pg
The number of images per row = $row
The number of rows per page = $numrow
image name array = $imagename
 */

$fsimg = ($pg - 1) * $galimg + 1;//first image

$onpage = $pg * $galimg;
$onpage = $images - $onpage;
$onpage = $onpage + $galimg;//total number of images on page
if ($onpage > 28) {
	$onpage = 28;
	}
$laimg = $fsimg + ($onpage - 1);//Last image

//How many rows?
if ($onpage <= 7) { //One row
	$numrow = 1;
	} elseif  ($onpage <= 14) { //Two rows
	$numrow = 2;
	} elseif  ($onpage <= 21) { //Three rows
	$numrow = 3;
	} elseif  ($onpage <= 28) { //Four rows
	$numrow = 4;
	}

//how many images in the last row?
$lastrow = ($numrow * 7) - $onpage;
$lastrow = 7 - $lastrow;



//Make number of images array
$imagename = range($fsimg, $laimg);



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gallery</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<body>
PHP scripted:
<table align="center">
<tr><td colspan="7" class="eventheader">Pictures</td></tr>



<?php
$y = 0;
for($x=0; $x < 28; $x++){
 // $total_images = the total number of images on the page
 if($x == $onpage){
   // Closes the row, ends the loop
   echo '</tr>';
   break;
 }

 if($y == 0){
   // Starts a new row
   echo '<tr>';
 }

 echo '<td class="eventheader"><a href="image.php?num='.$imagename.'"><img src="thumbs/'.$imagename.'.jpg" alt="Ninja" /></a></td>'."\n"; // \n is to help when viewing the html
 $y++; // Might need to move this a bit
 if($y == 7){
   // Ends the row, resets $y
   echo '</tr>';
   $y = 0;
 }
}
?>



</table>
</body>
</html>

I have most of the important parts of the code commented so it shouldn't be too hard for the experts here to know whats what and figure out whats wrong.


Anyway, thanks for getting me this far, and thanks to all that try to help me get to the end. :(

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 November 2005 - 09:12 PM

http://php.net/manua...ction.range.php
It's because $imagename is an array.

#6 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 13 November 2005 - 11:18 PM

Edit:
I got it working now.

I set $imagename to the first image number, and just had it add 1 to the $imagename after each echo.


Anyway, thanks for the help and will be sure to give credit for all the help you've given to me

Edited by FabianN, 14 November 2005 - 02:50 PM.


#7 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 15 November 2005 - 12:53 PM

fmod() is great for doing that as well.


basically find the remainder, and when it's equal to 0, that's the last row.

#8 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 15 November 2005 - 04:03 PM

SpaceGhost, we're two steps ahead of you.

Rather then using a function, we're using a symbol that does the exact same thing http://php.net/manua....arithmetic.php (%)

You should also note that Fabian's got it working now.

#9 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 22 November 2005 - 03:38 PM

:D DOH!

okay. :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users