Wow, I am tired. How is this for the code? I think it is really sloppy the way i am writting it, but it worked so far. Any suggestion on how to clean it up?
<?php require_once('Connections/mysqlcon.php'); ?>
<?php require_once('Connections/globalvar.php'); ?>
<?php
maximum number of photos displayed on an album page
define("MAX_DISPLAYED_PHOTOS","5");
mysql_select_db($database_mysqlcon, $mysqlcon);
$query_rs1 = "SELECT * FROM photo";
#$rs1 = mysql_query($query_rs1, $mysqlcon) or die(mysql_error());
$row_rs1 = mysql_fetch_assoc($rs1);
$totalRows_rs1 = mysql_num_rows($rs1);
$offset = isset($GET['offset']) ? $GET['offset'] : 0;
$offsetOriginal = $offset;
$photoQueryResult = retrieve_album_page($offset);
$totalRows = mysql_numrows($photoQueryResult);
$i = 1;
function retrieve_album_page($offset)
{
$rows = MAX_DISPLAYED_PHOTOS;
$query = "SELECT photoID, categories, subcategories, thumbnails, largenails, comments
FROM photo ORDER BY photoID LIMIT $offset, $rows";
$result = mysql_query($query);
return $result;
}
function next_page($offset)
{
$photoCount = retrieve_photo_count();
if ($offset < $photoCount) {
return "<a href='main.php?url=Images Gallery&offset=$offset'>Next Page</a> >>";
} else {
return "Next Page >>";
}
}
function previous_page($offset, $totalRows)
{
if ($offset - MAX_DISPLAYED_PHOTOS > 0)
{
$offset = $offset - $totalRows - MAX_DISPLAYED_PHOTOS;
return "<< <a href='main.php?url=Images Gallery&offset=$offset'>Previous Page</a>";
} else {
return "<< Previous Page";
}
}
Function: retrieve_photo_count()
Purpose: Determine total number of photos in album
function retrieve_photo_count()
{
$countQuery = "SELECT count(photoID) as photoCount FROM photo";
$countResult = mysql_query($countQuery);
return mysql_result($countResult,0,"photoCount");
}
Function: retrieve_photo()
Purpose: Retrieve information specific to a particular photo
function retrieve_photo($photoID)
{
$query = "SELECT photoID, categories, subcategories, thumbnails, largenails, comments FROM photo WHERE photoID='$photoID'";
$result = mysql_query($query);
return $result;
}
?>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tr>
<td></td>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="700">
<? while ($row_rs1 = mysql_fetch_assoc($photoQueryResult)) { ?>
<? if ($i == 1) { ?>
<tr>
<td width="20%"><img src="./pictures/thumbnails/<?php echo $row_rs1['thumbnails']; ?>"><br>
<?php echo $row_rs1['photoID']; ?> <?php echo $row_rs1['categories']; ?><br>
<?php echo $row_rs1['subcategories']; ?><br>
<?php echo $row_rs1['largenails']; ?><br>
<?php echo $row_rs1['comments']; ?></td>
<? $i++; } elseif ($i == 4) {?>
<td width="20%"><img src="./pictures/thumbnails/<?php echo $row_rs1['thumbnails']; ?>"><br>
<?php echo $row_rs1['photoID']; ?> <?php echo $row_rs1['categories']; ?><br>
<?php echo $row_rs1['subcategories']; ?><br>
<?php echo $row_rs1['largenails']; ?><br>
<?php echo $row_rs1['comments']; ?></td>
<? $i = "1"; } else { ?>
<td width="20%"><img src="./pictures/thumbnails/<?php echo $row_rs1['thumbnails']; ?>"><br>
<?php echo $row_rs1['photoID']; ?> <?php echo $row_rs1['categories']; ?><br>
<?php echo $row_rs1['subcategories']; ?><br>
<?php echo $row_rs1['largenails']; ?><br>
<?php echo $row_rs1['comments']; ?></td>
<? $i++;} ?>
<? $offset++; } ?>
<?php # $offset++; } while ($row_rs1 = mysql_fetch_assoc($photoQueryResult)); ?>
</table>
</td>
</tr>
</table>
<br>
<?php
echo previous_page($offset, $totalRows);
echo next_page($offset);
mysql_free_result($rs1);
?>