hello ppl,
I made a db photo galery, but i had as model a simple photo
galery which uses txt files for storing the names of files. I will
paste the bouth galery first will be the siple one and after that
will be the modified photo galery.
////////////////////////////////
// this is txt galery
///////////////////////////////
//initialize variables
$data_file = "list.photos";
$thumbnail_dir = "thumbs/";
$num_rows = 9;
$photos_per_row = 3;
$photos = file($data_file);
$total_photos = sizeof($photos);
$photos_per_page = $num_rows * $photos_per_row;
//check to see if the start variable exists in the URL.
//If not, then the user is on the first page - set start to 0
if(!isSet($start)){
$start = 0;
}
//init i to where it needs to start in the photos array
$i = $start;
$prev_start = $start - $photos_per_page;
$next_start = $start + $photos_per_page;
for ($row=0; $row < $num_rows; $row++){
print("<tr>\n");
for ($col=0; $col < $photos_per_row; $col++){
if($i < $total_photos){
$thumbnail = $thumbnail_dir.trim($photos[$i]);
$thumb_image_size = getimagesize($thumbnail);
$image_size = getimagesize(trim($photos[$i]));
print("<td class=\"button\" align=\"center\"><a href=\"javascript:photo_open('photo_display.php?photo=".trim($photos[$i])."','".$image_size[0]."',' ".$image_size[1]."');\"><img border=\"1\" src=\"".$thumbnail."\" ".$thumb_image_size[3]."></a></td>\n");
} else {
print("<td></td>\n");
}
$i++;
}
print("</tr>\n");
}
//end table
////////////////////////////////
// this is db galery
///////////////////////////////
require("db.inc.php");
$query = mysql_query("SELECT * FROM galerie_poze");
//numara poze din baza de date
$totalphotos = mysql_num_rows($query);
$rows = 9; // randuri pe pagina
$photos_per_row = 2; // cate poze pe rand
$photos_per_page = $rows * $photos_per_row;
echo "Poze pe pagina : $photos_per_page <br>";
// daca nu e setat eshti in prima pagina
if(!isSet($start)){
$start = 0;
}
// navigare in pagina
$i = $start;
$prev_start = $start - $photos_per_page;
$next_start = $start + $photos_per_page;
for ($row=0; $row < $rows; $row++){
print("<tr>\n");
for ($col=0; $col < $photos_per_row; $col++){
if($i < $totalphotos){
$picquery = mysql_query("SELECT * FROM galerie_poze"); // here is the problem
while($imgout = mysql_fetch_array($picquery)){
$thumbsize = "thumbs/galerie/".$imgout["poza"];
$imgsize = "galerie/".$imgout["poza"];
$thumb_image_size = getimagesize($thumbsize);
$image_size = getimagesize($imgsize);
print("<td class=\"button\" align=\"center\"><a href=\"javascript:photo_open('photo_display.php?photo=$imgsize','".$image_size[0]."',' ".$image_size[1]."');\"><img border=\"1\" src=\"$thumbsize\" ".$thumb_image_size[3]."></a></td>\n");
}
}
else{
print("<td></td>\n");
}
$i++;
}
print("</tr>\n");
}
The problem is where the pics are print out from the db, there is no limit and all the pics from db are printed in a single row. I tried to use LIMIT like this :
if(!isSet($limit)){
$limit = 0;
}
$limitend = $limit + $photos_per_row;
$picquery = mysql_query("SELECT * FROM galerie_poze LIMIT $limit,$limitend");
while(....){
....
}
$limit = $limitend;
... but it's not working well and I don't understand why 🙁. Firs
row is printed corectly but the next row has the last 2 photos
from the first row and all the photos from db.
If you have a better ideea on how I could do this plese give me
an reply.
10x and see ya soon