Forum Moderators: coopster
$dbhost="-----";
$dbusername="----";
$dbpassword="-----";
$dbname="----";
$mysql_link = $connect;
$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname,$connect) or die ("Could not select database");
$images_dir = 'photos';
$catid=$_REQUEST[catid];
if (isset($catid)) {
$data = mysql_query("SELECT * FROM gallery_photos WHERE photo_category=$catid ORDER BY photo_category_id ASC") or die(mysql_error());
}else{
$data = mysql_query("SELECT * FROM gallery_photos ORDER BY photo_category_id ASC") or die(mysql_error());
}
$rows = mysql_num_rows($data);
while($row_array=mysql_fetch_assoc($data))
{
$arr_cap[]=$row_array['photo_caption'];
$arr_img[]=$row_array['photo_filename'];
$total = $rows; //Total number of images in slideshow
$var_total = $rows+1; //Total number of images + 1
//Puts All Files In A Given Directory Into An Array
//If You Plan To Use This, Delete The Code For The Array Given Above
//$arr_img = Array();
//$handle = opendir(./img dir/);
//while (false!== ($file = readdir($handle))) {
// if ($file!= "." && $file!= "..") {
// $arr_img[] = $file;
// }
//}
//No Need to edit below here
$i = 1;
$next = 2;
$back = 0;
while($i <= $total){
if($back == 0) {
$back_link = $total;
} else {
$back_link = $back;
}
if($next == $var_total) {
$next_link = 1;
} else {
$next_link = $next;
}
if ($image == "$i") {
$next_img = "$next_link";
$back_img = "$back_link";
}
$i++;
$next++;
$back++;
}
}
?>
</CODE>
And this is my slide.php
<CODE>
<?
include("config.php");
$catid=$_REQUEST[catid];
if(!$catid) {
$catid=1;
}
if (!(isset($imagenum)))
{
$imagenum = 1;
}
$imgfilename = $arr_img[$image];
$photocaption = $arr_cap[$image];
if($_REQUEST[auto] == "on") {
$meta = "<meta http-equiv=\"refresh\" content=\"2;url=$PHP_SELF?image=$next_img&auto=on&catid=$catid \" />
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
$nav = "<a href=\"$PHP_SELF?image=$back_img&auto=on&catid=$catid \">Back</a> ¦
<a href=\"$PHP_SELF?image=$image&auto=off&catid=$catid \">Stop Slideshow</a> ¦
<a href=\"$PHP_SELF?image=$next_img&auto=on&catid=$catid \">Next</a>";
}
if($_REQUEST[auto] == "off" ¦¦!$_REQUEST[auto]) {
$meta = " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
$nav = "<a href=\"$PHP_SELF?image=$back_img&auto=off&catid=$catid \">Back</a> ¦
<a href=\"$PHP_SELF?image=$image&auto=on&catid=$catid \">Start Slideshow</a> ¦
<a href=\"$PHP_SELF?image=$next_img&auto=off&catid=$catid \">Next</a>";
}
echo<<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<head>
<title>Slideshow Bitches!</title>
$meta
</head>
<body>
EOF;
if(!$_REQUEST[image]) { //Default thumbnil page
$i = 0;
foreach($arr_img as $var_img) { //Grabs all the image names in th array
if($var_img!= "") { //Dont show first entery of the array that is blank
echo<<<EOF
<a href="$PHP_SELF?image=$i&catid=$catid"><img src="admin/photos/$var_img" width="240" height="180" /></a>
EOF;
}
$i++;
}
} else { //Show the slides
echo<<<EOF
<div align="center">
<img src="admin/photos/$arr_img[$image]" width="480" height="360" /><br /><br />
<p align="center">$photocaption</p><br />
$imgfilename<br />
$nav
</div>
EOF;
}//}
?>
</CODE>
Not any advanced stuff, got it from a tutorial. This is the default with preset filenames in the code:
<CODE>
$arr_img = array('', //empy array image set for [0]
'Stellar.jpg', //Image names to be displayed in the slideshow
'Submerged.jpg',
'b_luecrab.jpg',
'darkness.jpg');
</CODE>
Like you can see above, I tried getting the filenames from database, but then it ends up not being able to display the last image from the DB. It knows its there, through the row count, but it doesnt get the info from the database for it, or atleast doesnt show it. Note in the above code, he starts the array with an empty field. Any help much appreciated.
[edited by: ShoT at 11:04 pm (utc) on Dec. 31, 2007]
[edited by: eelixduppy at 12:27 am (utc) on Jan. 1, 2008]
[edit reason] removed password [/edit]