cgm225 Posted March 1, 2008 Share Posted March 1, 2008 I have the following code for generation of the footer on my photo/video pages. It contains a drop down form, and some links I am outputting. I want to know how to make the code more readable/pleasing to the eye. Generally I indent the code nicely, etc., but because I am outputting this form, and don't want to echo each line individually (I would have to escape all the quotations which is less than ideal), I am using the PRINT <<<END method, which I feel makes my code look like it's all over the place. Any ideas? Thank you all in advance! <?php if ($id == "videos") { print <<<END <form method="post" action="" style="margin:0;padding:0;"> <div style="float:right;padding:0 28px 4px 0;margin:0 0 0 0;"> END; } elseif ($id == "photos") { print <<<END <form method="post" action="" class="number_displayed"> <div class="number_displayed"> END; } if (permission_for("delete_album") == TRUE) {echo "\t\t\t\t<a href=\"http://www.example.com/albums/delete/$album\">Delete Album</a> | ";} ?>Display <select name="number_displayed" size="1" class="number_displayed" onchange="form.submit()"> <option value="2" class="number_displayed" <?php if ($number_displayed == 2) {echo "selected=\"selected\"";} ?>>2</option> <option value="4" class="number_displayed" <?php if ($number_displayed == 4) {echo "selected=\"selected\"";} ?>>4</option> <option value="6" class="number_displayed" <?php if ($number_displayed == 6) {echo "selected=\"selected\"";} ?>>6</option> <option value="8" class="number_displayed" <?php if ($number_displayed == {echo "selected=\"selected\"";} ?>>8</option> <option value="10" class="number_displayed" <?php if ($number_displayed == 10) {echo "selected=\"selected\"";} ?>>10</option> <option value="20" class="number_displayed" <?php if ($number_displayed == 20) {echo "selected=\"selected\"";} ?>>20</option> <option value="40" class="number_displayed" <?php if ($number_displayed == 40) {echo "selected=\"selected\"";} ?>>40</option> </select> <?php if ($id == "photos") { if ((mysql_num_rows(mysql_query("SELECT * FROM images WHERE album = $album_id ORDER BY timestamp DESC LIMIT $upper_limit, 1",$mysql_server_connection_1))) > 0) { echo "\t\t\t\t\t<a href='http://www.example.com/photos/$album/" . ($page + 1) . "'>Next</a>\n"; } elseif (file_exists("$server_video_album_location/$album")) { echo "\t\t\t\t\t<a href=\"http://www.example.com/videos/$album\">Next</a>\n"; } else { echo "\n"; } } elseif ($id == "videos") { //If there are more video entries beyond the upper MySQL limit a "Next" link will be provided if ((mysql_num_rows(mysql_query("SELECT * FROM videos WHERE album = $album_id ORDER BY timestamp DESC LIMIT $upper_limit, 1",$mysql_server_connection_1))) > 0) { echo "\t\t\t\t\t\t<a href='http://www.example.com/videos/$album/" . ($page + 1) . "'>Next</a>\n";} } print <<<END <noscript><p class="no_style">(JavaScript Required)</p></noscript> </div> </form> END; if ($id == "videos") { echo "\t\t\t\t\t<div class=\"spacer\"></div>\n"; echo "\t\t\t\t</div>\n"; echo "\t\t\t</div>\n"; } include_once "gallery.footer.inc.php"; ?> Quote Link to comment Share on other sites More sharing options...
toplay Posted March 1, 2008 Share Posted March 1, 2008 Make life easier on yourself and use a template engine. It will help you separate code/business logic from visual styling. I highly recommend Smarty http://www.smarty.net Quote Link to comment Share on other sites More sharing options...
cgm225 Posted March 1, 2008 Author Share Posted March 1, 2008 If I don't go that route, how would you revise the code above? Quote Link to comment Share on other sites More sharing options...
cgm225 Posted March 2, 2008 Author Share Posted March 2, 2008 bump - Any other ideas? I just don't want to use Smarty due to the small size of this project. Quote Link to comment Share on other sites More sharing options...
maexus Posted March 2, 2008 Share Posted March 2, 2008 Writing your own page class with template parser? Writing it yourself means you can make it portable to other projects while keeping it neat and slim. 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.