Page 1 of 1

Trouble programming my own photo gallery

Posted: Fri Apr 09, 2010 6:21 pm
by Bjeffries111
I originally started out by reading PHP/Mysql for dummies and doing many online tutorials and still cannot seem to program my own code that works.

So I have two pages:
photo.php - which calls on the album thumbnails and seems to work successfully. Although, I believe I am using amateur coding.

Code: Select all

$con = mysql_connect("...","...","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("...", $con);

$result = mysql_query("SELECT * FROM photo_albums ORDER BY uptime DESC");


while($row = mysql_fetch_array($result))
  {

  echo '<div class="photoThumb">';
  echo '<a href="viewAlbum.php?aid='.$row['aid'].'"><img src="' . $row['filepath'];
  echo $row['filename'] . '"';
  echo 'border="0" /></a>';
  echo '<br/>';
  echo '<span class="thumbText"><a href="viewAlbum.php?aid='.$row['aid'].'">' . $row['stitle'];
  echo  '</a><br/>';
  echo $row['photog'];
  echo '</span>';
  echo "</div>";
  }

mysql_close($con);
viewAlbum.php - this is the one I am having trouble on. I have used a ton of different ways to write the code and some seem to somewhat work, others do not.

Code: Select all

$con = mysql_connect("...","...","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("...", $con);


$result = mysql_query("SELECT *
FROM `pictures` WHERE `aid` = 1 ORDER BY `pid` ASC");


while($row = mysql_fetch_array($result))
  {
  echo '<div class="photoThumb">';
  echo '<a href="';
  echo $row['filepath'];
  echo $row['filename'];
  echo '"><img src="';
  echo $row['filepath'];
  echo $row['filename'];
  echo '" rel="lightbox[' .$row['aid'];
  echo ']" border="0" width="100px" /></a><br/>';
  echo "</div>";
  }
mysql_close($con);
My problem is I cannot have album 1 always showing on all links.

How do I make just the album the user clicked on display?

Also, does any one know how to get the lightbox to work?

Code: Select all

echo '" rel="lightbox[' .$row['aid'];
That also doesnt work.

Thanks for the time,
Brian

Re: Trouble programming my own photo gallery

Posted: Fri Apr 09, 2010 10:41 pm
by jthermane24
Your photo.php script does seem to work.

As for the album page you could append the album to view on the end of the url in a variable (www.blahblah.domain/page.php?variable=value) and have the script in the page $_GET['variable'] and assign it to $var and run the script using that album to view (change aid = 1 in the query to aid = $val).

Although, that would require you adding a page that asks for the album to view or setting the link that loads the page to include the variable. This could be added in a thousand and a half different ways. A popup could appear on the page onload() (javascript) to ask for the album id, or you could redirect to a page displaying a form asking for the link and then redirecting back to album.php (or whatever it may be named). Just use google, it is your friend. I was in your boat once, and at points I still am, it takes a while to master coding. Just remember to be patience, you will run into problems it happens to me every day.