| | |
Php Gallery
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 41
Reputation:
Solved Threads: 1
I'm trying to develop a web gallery, but have been struggling with laying out the thumbnails, and paginating the results. I found a tutorial, but have been experiencing problems with it. Can anyone point me in the right direction?
Current result: http://www.equinefocus.co.uk//photos...21/gallery.php
Current code:
Attached is a screenshot of my current database table.
Current result: http://www.equinefocus.co.uk//photos...21/gallery.php
Current code:
PHP Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("*****") or die ("Unable to connect to MySQL"); // How many pictures to display on each page. $picsperpage = 12; // How many pictures to display per row. $picsperrow = 4; // images $thumb ='/photos/'.$info['date'].'/thumbs/'.$info['thumb']; $url ='/photos/'.$info['date'].'/'.$info['url']; // If the page number is set... if(isset($_GET['p'])) { // $page is now the page number. $page = $_GET['p']; } else { // Otherwise the page is 1. $page = 1; } // What the starting number will be for the query. $start = ($page - 1) * $picsperpage; // Counts all of the rows in the table. $res= @mysql_query("SELECT COUNT(id) AS numrows FROM photos") or die("Sorry, but there was an error retrieving the gallery."); // Gets the number of rows from the array. $fetchres = @mysql_fetch_array($res, MYSQL_ASSOC) or die("Sorry, but there was an error retrieving the gallery."); $numrows = $fetchres['numrows']; // How many pages there will be (total pictures / # of pictures per page). $totalpages = ceil($numrows/$picsperpage); echo '<ul>'; // Echos our page numbers so that we can navigate. for($i=1; $i <= $totalpages; $i++) { if($i == $page) { // If it's the current page, don't make a link since we are already there. echo '<li>' . $i . '</i>'; } else { // Make all other pages links. echo '<li><a href="main.php?p=' . $i . '">' . $i . '</a></li>'; } } echo '</ul><br /> <div class="gallery">'; // Get all of the pictures for the current page. $allphotos = @mysql_query("SELECT * FROM photos LIMIT $start, $picsperpage") or die("Sorry, but there was an error retrieving the gallery."); // How many pictures there are right now. $rowcount = 0; // For each row in the gallery table... while ($row = @mysql_fetch_array($allphotos)) { // If $rowcount divided by $picsperrow has a remainder of 0... if (($rowcount % $picsperrow) == 0) { // Make a <br /> tag with a clear both style, so that there is a new row of images echo '<br style="clear: both;" />'; } // Displaying each image with this code. echo '<a href="' . $row['thumb']. '"><img src="' . $row['url']. '" /></a>'; // $rowcount + 1. $rowcount++; } // After all the images are done, end the div. echo '</div>'; ?>
Attached is a screenshot of my current database table.
Looking at your code, I think you have your variables in a mix:
Would output (for row 1)
Swap over the variables so that the thumb is in the img tag and the url is in the a tag.
php Syntax (Toggle Plain Text)
echo '<a href="' . $row['thumb']. '"><img src="' . $row['url']. '" /></a>';
html Syntax (Toggle Plain Text)
<a href="001.jpg"><img src="001.php" /></a>
Swap over the variables so that the thumb is in the img tag and the url is in the a tag.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Can you post the rest of your script?
I have setup a table on my database and a slightly modified script on the server and it works for me.
Here's the edited code
See it here: clicky
I have setup a table on my database and a slightly modified script on the server and it works for me.
Here's the edited code
php Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("***", "***", "***")or die(mysql_error()); mysql_select_db("***")or die ("Unable to connect to MySQL"); // How many pictures to display on each page. $picsperpage = 12; // How many pictures to display per row. $picsperrow = 4; // images $thumb ='/photos/'.$info['date'].'/thumbs/'.$info['thumb']; $url ='/photos/'.$info['date'].'/'.$info['url']; // If the page number is set... if(isset($_GET['p'])) { // $page is now the page number. $page = $_GET['p']; } else { // Otherwise the page is 1. $page = 1; } // What the starting number will be for the query. $start = ($page - 1) * $picsperpage; // Counts all of the rows in the table. $res= @mysql_query("SELECT COUNT(id) AS numrows FROM photos")or die("Sorry, but there was an error retrieving the gallery."); // Gets the number of rows from the array. $fetchres = @mysql_fetch_array($res, MYSQL_ASSOC)or die("Sorry, but there was an error retrieving the gallery."); $numrows = $fetchres['numrows']; // How many pages there will be (total pictures / # of pictures per page). $totalpages = ceil($numrows/$picsperpage); echo '<ul>'; // Echos our page numbers so that we can navigate. for($i=1; $i <= $totalpages; $i++) { if($i == $page) { // If it's the current page, don't make a link since we are already there. echo '<li>' . $i . '</i>'; } else { // Make all other pages links. echo '<li><a href="main.php?p=' . $i . '">' . $i . '</a></li>'; } } echo '</ul><br /> <div class="gallery">'; // Get all of the pictures for the current page. $allphotos = @mysql_query("SELECT * FROM photos LIMIT $start, $picsperpage")or die("Sorry, but there was an error retrieving the gallery."); // How many pictures there are right now. $rowcount = 0; // For each row in the gallery table... while ($row = @mysql_fetch_array($allphotos)) { // If $rowcount divided by $picsperrow has a remainder of 0... if (($rowcount % $picsperrow) == 0) { // Make a <br /> tag with a clear both style, so that there is a new row of images echo '<br style="clear: both;" />'; } // Displaying each image with this code. echo '<a href="' . $row['url'] . '"><img src="' . $row['thumb'] . '" /></a>'; // $rowcount + 1. $rowcount++; } // After all the images are done, end the div. echo '</div>'; ?>
See it here: clicky
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Apr 2008
Posts: 41
Reputation:
Solved Threads: 1
Thanks, appreciate the trouble you're going to.
I've looked at your link, and attach a screenshot of how I see it. The code in it's entirety is below.
I've been playing all afternoon, and have almost given up - I've reproduced the gallery with CSS to position the items - out of interest, is it possible to paginate results without use of a table, just stipulate how many thumbnails are to appear on each page?
Look forward to hearing your advice.
I've looked at your link, and attach a screenshot of how I see it. The code in it's entirety is below.
PHP Syntax (Toggle Plain Text)
<!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" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Equine Focus</title> </head> <body> <?php // Connects to your Database mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("*****") or die ("Unable to connect to MySQL"); // How many pictures to display on each page. $picsperpage = 12; // How many pictures to display per row. $picsperrow = 3; // images $thumb ='/photos/'.$info['date'].'/thumbs/'.$info['thumb']; $url ='/photos/'.$info['date'].'/'.$info['url']; // If the page number is set... if(isset($_GET['p'])) { // $page is now the page number. $page = $_GET['p']; } else { // Otherwise the page is 1. $page = 1; } // What the starting number will be for the query. $start = ($page - 1) * $picsperpage; // Counts all of the rows in the table. $res= @mysql_query("SELECT COUNT(id) AS numrows FROM photos") or die("Sorry, but there was an error retrieving the gallery."); // Gets the number of rows from the array. $fetchres = @mysql_fetch_array($res, MYSQL_ASSOC) or die("Sorry, but there was an error retrieving the gallery."); $numrows = $fetchres['numrows']; // How many pages there will be (total pictures / # of pictures per page). $totalpages = ceil($numrows/$picsperpage); echo '<ul>'; // Echos our page numbers so that we can navigate. for($i=1; $i <= $totalpages; $i++) { if($i == $page) { // If it's the current page, don't make a link since we are already there. echo '<li>' . $i . '</i>'; } else { // Make all other pages links. echo '<li><a href="main.php?p=' . $i . '">' . $i . '</a></li>'; } } echo '</ul><br /> <div class="gallery">'; // Get all of the pictures for the current page. $allphotos = @mysql_query("SELECT * FROM photos LIMIT $start, $picsperpage") or die("Sorry, but there was an error retrieving the gallery."); // How many pictures there are right now. $rowcount = 0; // For each row in the gallery table... while ($row = @mysql_fetch_array($allphotos)) { // If $rowcount divided by $picsperrow has a remainder of 0... if (($rowcount % $picsperrow) == 0) { // Make a <br /> tag with a clear both style, so that there is a new row of images echo '<br style="clear: both;" />'; } // Displaying each image with this code. echo '<a href="' . $url. '"><img src="' . $thumb. '" /></a>'; // $rowcount + 1. $rowcount++; } // After all the images are done, end the div. echo '</div>'; ?>
I've been playing all afternoon, and have almost given up - I've reproduced the gallery with CSS to position the items - out of interest, is it possible to paginate results without use of a table, just stipulate how many thumbnails are to appear on each page?
Look forward to hearing your advice.
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
•
•
•
•
Can you post the rest of your script?
I have setup a table on my database and a slightly modified script on the server and it works for me.
Here's the edited code
php Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("***", "***", "***")or die(mysql_error()); mysql_select_db("***")or die ("Unable to connect to MySQL"); // How many pictures to display on each page. $picsperpage = 12; // How many pictures to display per row. $picsperrow = 4; // images $thumb ='/photos/'.$info['date'].'/thumbs/'.$info['thumb']; $url ='/photos/'.$info['date'].'/'.$info['url']; // If the page number is set... if(isset($_GET['p'])) { // $page is now the page number. $page = $_GET['p']; } else { // Otherwise the page is 1. $page = 1; } // What the starting number will be for the query. $start = ($page - 1) * $picsperpage; // Counts all of the rows in the table. $res= @mysql_query("SELECT COUNT(id) AS numrows FROM photos")or die("Sorry, but there was an error retrieving the gallery."); // Gets the number of rows from the array. $fetchres = @mysql_fetch_array($res, MYSQL_ASSOC)or die("Sorry, but there was an error retrieving the gallery."); $numrows = $fetchres['numrows']; // How many pages there will be (total pictures / # of pictures per page). $totalpages = ceil($numrows/$picsperpage); echo '<ul>'; // Echos our page numbers so that we can navigate. for($i=1; $i <= $totalpages; $i++) { if($i == $page) { // If it's the current page, don't make a link since we are already there. echo '<li>' . $i . '</i>'; } else { // Make all other pages links. echo '<li><a href="main.php?p=' . $i . '">' . $i . '</a></li>'; } } echo '</ul><br /> <div class="gallery">'; // Get all of the pictures for the current page. $allphotos = @mysql_query("SELECT * FROM photos LIMIT $start, $picsperpage")or die("Sorry, but there was an error retrieving the gallery."); // How many pictures there are right now. $rowcount = 0; // For each row in the gallery table... while ($row = @mysql_fetch_array($allphotos)) { // If $rowcount divided by $picsperrow has a remainder of 0... if (($rowcount % $picsperrow) == 0) { // Make a <br /> tag with a clear both style, so that there is a new row of images echo '<br style="clear: both;" />'; } // Displaying each image with this code. echo '<a href="' . $row['url'] . '"><img src="' . $row['thumb'] . '" /></a>'; // $rowcount + 1. $rowcount++; } // After all the images are done, end the div. echo '</div>'; ?>
See it here: clicky
#
// How many pictures to display on each page.
#
$picsperpage = 12;
#
// How many pictures to display per row.
#
$picsperrow = 4;
should be 12 and 4 per rows
may I request to "Borderline" can you dump your SQL file.
can you post also your <div class="gallery">'; on your CSS.
Last edited by rm_daniweb; Apr 5th, 2009 at 6:07 pm.
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
http://www.equinefocus.co.uk//photos...21/gallery.php
why is it there are 2 double '//' on your link?
I think you have errors on your path...
why is it there are 2 double '//' on your link?
I think you have errors on your path...
Last edited by rm_daniweb; Apr 5th, 2009 at 6:23 pm.
I think I see the problem:
You have this at the top of the script:
But at that point $info has not been declared/defined, you can confirm this by looking at your source on the actual page, it is missing the values so you end up with the image src being '/photos//thumbs/' for every image.
This should be within the while statement after the SQL query, so change:
To
That should work.
You have this at the top of the script:
php Syntax (Toggle Plain Text)
// images $thumb ='/photos/'.$info['date'].'/thumbs/'.$info['thumb']; $url ='/photos/'.$info['date'].'/'.$info['url'];
But at that point $info has not been declared/defined, you can confirm this by looking at your source on the actual page, it is missing the values so you end up with the image src being '/photos//thumbs/' for every image.
This should be within the while statement after the SQL query, so change:
php Syntax (Toggle Plain Text)
// Displaying each image with this code. echo '<a href="' . $url. '"><img src="' . $thumb. '" /></a>';
php Syntax (Toggle Plain Text)
// Image Declarations $thumb ="/photos/" . $row['date'] . "/thumbs/" . $row['thumb']; $url ="/photos/" . $row['date'] . "/" . $row['url']; // Displaying each image with this code. echo '<a href="' . $url. '"><img src="' . $thumb. '" /></a>';
That should work.
Last edited by Will Gresham; Apr 5th, 2009 at 7:02 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Similar Threads
- Upload image using PHP and AJAX (PHP)
- PHP Members HELP W/DB Images (PHP)
- Website Gallery (Existing Scripts)
- what to do with this .SQL script? (MySQL)
- php photo gallery extra code needed (PHP)
- Php portal install help!! (PHP)
- Why is this happening to my table????!!!! (HTML and CSS)
- My little particle engine (Game Development)
Other Threads in the PHP Forum
- Previous Thread: Subdomain Drupal
- Next Thread: Script to add url to text file
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web webdesign websphere white xml youtube





