cgm225 Posted March 12, 2008 Share Posted March 12, 2008 The following is basically the core of a simple photo/video gallery I coded, and I wanted to know if there were any ways to improve it (i.e. syntax, making the code shorter/more efficient, commenting, etc)? I would appreciate any constructive criticism you many have! Thank you all in advance! <?php //Enable full error reporting //error_reporting(E_ALL); /*//////General gallery includes, variables, etc.//////////////////////////////////////////////////////////// */ include_once "gallery.configurations.inc.php"; include_once "gallery.functions.inc.php"; //Getting required variables $id = $_GET['id']; $album = $_GET['album']; $page = $_GET['page']; if (!$page) {$page = 1;} $image = $_GET['image']; /*//////////////////////////////////////////////////////////////////////////////////////// // // 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 $mysql_server_connection_1 = mysql_connect($mysql_server_1,$mysql_server_1_username,$mysql_server_1_password,new_link); mysql_select_db($gallery_database, $mysql_server_connection_1); //Will create tables (as outlined above), if not already present include_once "action_table_generation.inc.php"; //Gathering information and running actions for the pages with multiple photo and videos if ($album != ""){ //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; } //Bringing in album information from MySQL gallery database, album table $album_query = "SELECT * FROM albums WHERE dir = '$album'"; $album_results = mysql_fetch_array(mysql_query($album_query,$mysql_server_connection_1)); $album_id = $album_results['id']; $full_title = $album_results['full_title']; /*//////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'",$mysql_server_connection_1)); if ($number_of_image_files != $number_of_mysql_image_entries) { include_once "action_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 $image_query = "SELECT * FROM images WHERE album = $album_id"; $number_of_images = mysql_num_rows(mysql_query($image_query,$mysql_server_connection_1)); //Calculating total number of photo pages $number_of_photo_pages = ceil($number_of_images / $number_displayed); /*//////Generating image thumbnails if not already done//////////////////////////////////////////////// */ $number_of_thumbnail_files = count(glob("$server_photo_thumbnail_location/$album/*.*")); if ($number_of_thumbnail_files != ($number_of_images * 2)) { include_once "action_thumbnail_generation.inc.php";} /*//////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'",$mysql_server_connection_1)); if ($number_of_video_files != $number_of_mysql_video_entries) { include_once "action_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,$mysql_server_connection_1)); //Calculating total number of video pages $number_of_video_pages = ceil($number_of_videos / $number_displayed); } //Gathering information and running actions for the pages with a single photo if ($image != "") { //Retrieving query of image for any one particular page $query = "SELECT * FROM images WHERE album = $album_id ORDER BY filename ASC LIMIT $image, 1"; $specific_image = mysql_query($query,$mysql_server_connection_1); while($row = mysql_fetch_array($specific_image)) { $image_id = $row['id']; $filename = $row['filename']; $caption = stripslashes($row['caption']); $date = stripslashes($row['date']); $location = stripslashes($row['location']);} } ?> Quote Link to comment Share on other sites More sharing options...
cgm225 Posted March 12, 2008 Author Share Posted March 12, 2008 bump Quote Link to comment Share on other sites More sharing options...
keeB Posted March 18, 2008 Share Posted March 18, 2008 I guess my help in the OOP section wasn't enough. 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.