cgm225 Posted February 20, 2008 Share Posted February 20, 2008 I am currently using the script below as a header for my php gallery application. However, I wanted to use it as a learning experience, and see if there were things I could be doing better. In particular, I am basically using the same code twice to add new images and then, later, new videos, to the MySQL database. Is there a way to combine those to pieces of code into something more efficient? Do you have any other suggestions? Tear it apart! Thank you all in advance! <?php /*//////General gallery includes, variables, etc.//////////////////////////////////////////////////////////// */ include_once "gallery.configurations.inc.php"; include_once "gallery.functions.inc.php"; //Getting required variables $album = $_GET['album']; $page = $_GET['page']; if (!$page) {$page = 1;} $image = $_GET['image']; //If there is no album directory by that name, will send the user to an error page if (($album != "") AND (!file_exists("$server_photo_album_location/$album/")) AND (!file_exists("$server_video_album_location/$album/"))) { header("Location:http://www.example.com/home/error");} //If the photo album is restricted by .htaccess, will also add authentication as well if ((file_exists("$server_photo_album_location/$album/.htaccess")) OR (file_exists("$server_video_album_location/$album/.htaccess"))) { general_permissions();} /* Will determine the number of photos to display based on a default value or on a user selected value from a form at the bottom of the page main album page */ if (!$_POST["number_displayed"]) { if (!$_SESSION['number_displayed']) { $number_displayed = 2; } else { $number_displayed = $_SESSION['number_displayed']; } } else { $number_displayed = $_POST["number_displayed"]; $_SESSION['number_displayed'] = $number_displayed; } /*//////////////////////////////////////////////////////////////////////////////////////// // // Database Name: Gallery // Database Structure // // Albums Table: id || full_title || short_title || dir || timestamp // | // +----------------------------------------------------+ // | // Images Table: id || filename || caption date || location || album || timestamp // | // +------------------+ // | // Videos Table: id || filename || title || album || timestamp // ////////////////////////////////////////////////////////////////////////////////////////*/ //Connecting to MySQL gallery database gallery_db_connect(); //Will create tables (as outlined above), if not already present include_once "gallery.table.generation.inc.php"; //Bringing in album information from MySQL gallery database, album table $query = "SELECT * FROM albums WHERE dir = '$album'"; $album_results = mysql_fetch_array(mysql_query($query)); $album_id = $album_results['id']; $full_title = $album_results['full_title']; //Setting page title plain_page_title($full_title); if ($album_id != "") { /*//////Adding any new images to the MySQL gallery database//////////////////////////////////////////// */ $number_of_image_files = count(glob("$server_photo_album_location/$album/*.*")); $number_of_mysql_image_entries = mysql_num_rows(mysql_query("SELECT * FROM images WHERE album = '$album_id'")); if ($number_of_image_files != $number_of_mysql_image_entries) { include_once "gallery.add.images.inc.php";} /*//////Retrieving the total number of photos and photo pages////////////////////////////////////////// */ //Finding the total number of images for any particular album from MySQL gallery database, images table $query = "SELECT * FROM images WHERE album = $album_id"; $number_of_images = mysql_num_rows(mysql_query($query)); //Calculating total number of photo pages $number_of_photo_pages = ceil($number_of_images / $number_displayed); /*//////Adding any new videos to the MySQL gallery database//////////////////////////////////////////// */ $number_of_video_files = count(glob("$server_video_album_location/$album/*.*")); $number_of_mysql_video_entries = mysql_num_rows(mysql_query("SELECT * FROM videos WHERE album = '$album_id'")); if ($number_of_video_files != $number_of_mysql_video_entries) { include_once "gallery.add.videos.inc.php";} /*//////Retrieving the total number of videos and video pages////////////////////////////////////////// */ //Finding the total number of videos for any particular album from MySQL gallery database, videos table $query = "SELECT * FROM videos WHERE album = $album_id"; $number_of_videos = mysql_num_rows(mysql_query($query)); //Calculating total number of video pages $number_of_video_pages = ceil($number_of_videos / $number_displayed); } ?> Quote Link to comment Share on other sites More sharing options...
cgm225 Posted February 20, 2008 Author Share Posted February 20, 2008 bump Quote Link to comment Share on other sites More sharing options...
cgm225 Posted February 20, 2008 Author Share Posted February 20, 2008 ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.