Version: 1.3
Type: Full Script
Category: Databases
License: GNU General Public License
Description: A php and mysql template to speed up php and mysql program developement
Now with classes
<?
include("./include/connection.php");
print"<html>
<HEAD>
<TITLE>Story Management</TITLE>
</HEAD>
<link rel=\"stylesheet\" href=\"./css/default.css\" type=\"text/css\">
<BODY text=\"#000000\" vLink=\"#5493b4\" link=\"#006699\" bgColor=\"#3a6ba5\">
<TABLE cellSpacing=\"0\" cellPadding=\"10\" width=\"100%\" align=\"center\" border=\"0\">
<TBODY>
<TR>
<TD class=\"bodyline\">";
print"<h1>$categoryname</h1><br>";
print"<a href=\"manages.php?mode=1\"><img border=\"0\" src=\"image/post.gif\" width=\"82\" height=\"25\" alt=\"Add new information\"></a>";
print"<TABLE class=\"forumline\" cellSpacing=\"1\" cellPadding=\"3\" width=\"645\"
border=\"0\">
<TBODY>
<TR>
<TH class=\"thHead\" height=\"25\" width=\"629\" colspan=\"3\">
<b>View</b>
</TH>
</TR>
<TR>
<TD class=\"row1\" width=\"619\" valign=\"top\" align=\"right\" colspan=\"3\">";
// set per page view
$limit="3";
// first page offset equal to 0
if (empty($offset)) {
$offset =0;
}
if($row && $sort) {
$total_query="select id from story where $row like '$sort%' ";
$sql="select * from story where $row like '$sort%' desc limit $offset,$limit";
}
elseif($datasearch) {
$total_query="select id from story where $row like '$datasearch' ";
$sql="select * from story where $row like '$datasearch' order by 'id' desc limit $offset,$limit ";
}
else {
$total_query="select id from story";
$sql="SELECT * from story order by id desc limit $offset,$limit";
}
$countRecord=mysql_query($total_query,$connect)or die (mysql_errno()."<br>". mysql_error()."total query count problem");
$numrows = mysql_num_rows($countRecord);
$result =mysql_query($sql,$connect)or die (mysql_errno()."<br>". mysql_error()."data output problem");
class navigation {
function first_lastpage($offset,$row,$sort,$datasearch,$numrows) {
$lastpage=$numrows - 1 ;
if($row && $sort) {
print"<a href=\"$PHP_SELF?\">[Reset Finding]</a>
<a href=\"$PHP_SELF?offset=0&row=$row&sort=$sort\">[First Page] </a> ";
print"<a href=\"$PHP_SELF?offset=$lastpage&row=$row&sort=$sort\"> [Last Page] </a> ";
}
elseif($datasearch){
print"<a href=\"$PHP_SELF?category=$category\">[Reset Finding]</a><a href=\"$PHP_SELF?offset=0&datasearch=$datasearch&category=$category\">[First Page] </a> ";
print"<a href=\"$PHP_SELF?offset=$lastpage&datasearch=$datasearch\"> [Last Page] </a> ";
}
else {
print"<a href=\"$PHP_SELF?\">[First Page] </a> ";
print"<a href=\"$PHP_SELF?offset=$lastpage\"> [Last Page] </a> ";
}
}
function next_page($offset,$row,$sort,$datasearch,$numrows,$limit) {
if($offset >= 1) {
$prevoffset = $offset - $limit ;
if($row && $sort) {
print"<a href=\"$PHP_SELF?offset=$prevoffsetsort=$sort&row=name\"><img border=\"0\" src=\"image/prev.gif\"> Previous </a> ";
}
elseif($datasearch) {
print"<a href=\"$PHP_SELF?offset=$prevoffset&row=$row&datasearch=$datasearch\"><img border=\"0\" src=\"image/prev.gif\">Previous </a> ";
}
else{
print"<a href=\"$PHP_SELF?offset=$prevoffset\"><img border=\"0\" src=\"image/prev.gif\"> Previous </a> ";
}
}
}
function prev_page($offset,$row,$sort,$datasearch,$numrows,$limit) {
$lastpage=$numrows - 1 ;
$pages=intval($numrows/$limit);
if($numrows % $limit) {
$pages ++;
}
if ($pages!=1 or (($pages==1 and ($numrows%$limit)))) {
$newoffset =$offset +$limit ;
if($row && $sort) {
print"<a href=\"$PHP_SELF?offset=$newoffset$sort&row=name\"><img border=\"0\" src=\"image/next.gif\"> Next </a> ";
}
elseif($datasearch) {
print"<a href=\"$PHP_SELF?offset=$newoffset&row=$row&datasearch=$datasearch\"><img border=\"0\" src=\"image/next.gif\"> Next </a> ";
}
else {
print"<a href=\"$PHP_SELF?offset=$newoffset\"><img border=\"0\" src=\"image/next.gif\"> Next </a> ";
}
}
}
}
$navigation = new navigation ;
echo $navigation->first_lastpage($offset,$row,$sort,$datasearch,$numrows);
echo $navigation->next_page($offset,$row,$sort,$datasearch,$numrows,$limit);
echo $navigation->prev_page($offset,$row,$sort,$datasearch,$numrows,$limit);
if(($offset < 0)or($offset > $numrows)) {
echo message("Admin Message","Not Found <br><a href=\"$PHP_SELF?category=$category\">Please click to reset search result</a><img src=\"smiles/smile.gif\">");
}
else {
if($numrows >=1) {
while ($row = mysql_fetch_array($result)){
print"</td>
</TR>
<TR>
<TD class=\"row1\" width=\"542\"></TD>
<TD class=\"row1\" width=\"42\">
<a href=\"manages.php?mode=2&id=$row[id]\">
<img src=\"image/icon_edit.gif\" width=\"59\"
height=\"18\" border=\"0\" alt=\"add current information\">
</a>
</TD>
<TD class=\"row1\" width=\"35\"><a href=\"manages.php?mode=3&id=$row[id]\">
<img src=\"image/icon_delete.gif\" width=\"16\" height=\"18\" border=\"0\"
alt=\"Are sure you want to delete this information\"></a></TD>
</TR>
<TR>
<TD class=\"row1\" width=\"619\" colspan=\"3\">";
print"<font color=\"black\">Id : $row[id]<br>
Name : $row[name]<br>
Story : $row[story]</font><br>
</TD>
</TR>";
// end loop
}
}
else {
echo message("Admin Message","Not Found <br><a href=\"$PHP_SELF\">Please click to reset search result</a><img src=\"smiles/confuse.gif\">");
}
}
print"<TR>
<TD class=\"row1\" width=\"619\" valign=\"top\" align=\"right\" colspan=\"3\">";
echo $navigation->first_lastpage($offset,$row,$sort,$datasearch,$numrows);
echo $navigation->next_page($offset,$row,$sort,$datasearch,$numrows,$limit);
echo $navigation->prev_page($offset,$row,$sort,$datasearch,$numrows,$limit);
print"</TD>
</TR>
</TBODY>
</TABLE>";
// both two include are optional
include("./include/sort.php");
include("./include/search.php");
print"</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</html>"; ?>