I am working on php and mysql. Want to do pagination.
Here is my flow:
In the Login page user upload the document by giving there first_name, last_name, etc. In the login page also I have added search functionality. As per the query in the search field i am displaying the record.
Right now I am able to displaying the record as per the search query but i want to add paging in the code. here is the code:
My Home.html page code:
my searchdb.php code is:
Here is my flow:
In the Login page user upload the document by giving there first_name, last_name, etc. In the login page also I have added search functionality. As per the query in the search field i am displaying the record.
Right now I am able to displaying the record as per the search query but i want to add paging in the code. here is the code:
My Home.html page code:
Code:
<!DOCTYPE html>
<head>
<title>Upload & Download Document</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(auther_first_name,"Auther First Name must be filled out!")==false)
{auther_first_name.focus();return false;}
if (validate_required(auther_last_name,"Auther Last Name must be filled out!")==false)
{auther_last_name.focus();return false;}
if(thisform['auther_first_name'].value == thisform['auther_last_name'].value) {
alert('auther_first_name should not equals to auther_last_name');
return false;
}
if (validate_required(topic_title,"Topic Title must be filled out!")==false)
{topic_title.focus();return false;}
if (validate_required(uploaded_file,"Please Browse the file you want to upload!")==false)
{uploaded_file.focus();return false;}
}
}
function validate_required1(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form1(thisform)
{
with (thisform)
{
if (validate_required1(searchterm,"What you want to Search!")==false)
{searchterm.focus();return false;}
}
}
</script>
</head>
<body bgcolor="#ffffcc">
<br>
<table ALIGN="CENTER">
<tr>
<td>
<a href="Home.html">
<img src="metasession_document_repository.png"/></a>
</td>
</tr>
</table>
<br>
<hr size=10px color=darkblue>
<font size="+3" color="green" ></font>
<form action="add_file.php" onsubmit="return validate_form(this)" method="post" enctype="multipart/form-data">
<table ALIGN="CENTER">
<tr><td>
Fill your details Before uploading document !
</td></tr>
</table>
<table style="background-color: #ECE5B6;" width="30%" height="40%" ALIGN="CENTER">
<br />
<tr>
<th width="50%">Auther First Name:</th>
<td width="50%"><INPUT type="text" name="auther_first_name"></td>
</tr>
<tr>
<th width="50%">Auther Last Name:</th>
<td width="50%"><input type="text" name="auther_last_name"></td>
</tr>
<tr>
<th width="50%">Topic Title:</th>
<td width="50%"><input type="text" name="topic_title"></td>
</tr>
<tr>
<th width="100%" height="100%">Description:</th>
<td width="100%" height="100%"><input type="text" name="description" maxlength="200"></td>
</tr>
<tr>
<th width="50%">Upload File:</th>
<td width="50%"><input type="file" name="uploaded_file"></td>
</tr>
<tr>
<th></th>
<td width="50%"><INPUT TYPE="submit" VALUE="Upload file"></td>
</tr>
</table>
</form>
</br>
<form>
<table style="background-color: #ECE5B6;" width="34%" ALIGN="CENTER">
<tr>
<td>
<a href="displayRecord.php">Click To See The List of Document Uploaded in Database Till Now</a>
</td>
</tr>
</table>
</form>
</br>
</br>
</br>
</br>
</br>
</br>
<form action="searchdb.php" onsubmit="return validate_form1(this)" method="post">
<table width="50%" ALIGN="CENTER">
Search by <select size="1" name="selectfromlist" >
<option value="auther_first_name">Auther Name</option>
<option value="topic_title">Topic Title</option>
<option value="data">Document</option>
</select>
</br>
</br>
<input type="text" size="100" name="searchterm"/>
</br>
</br>
<tr>
<input type="submit" size = "10" value="Go">
</td>
</table>
</form>
</body>
</html>
Code:
<html>
<body bgcolor="#ffffcc">
<br>
<table ALIGN="CENTER">
<tr>
<td>
<a href="Home.html">
<img src="metasession_document_repository.png"/></a>
</td>
</tr>
</table>
<br>
<?php
$space=" ";
/*set varibles from form */
$searchterm = $_POST['searchterm'];
$selectfromlist = $_POST['selectfromlist'];
trim ($searchterm);
trim ($selectfromlist);
if (!$searchterm){
}
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}
/* connects to database */
@ $dbconn = new mysqli('localhost', 'aaa', 'aaa', 'upload_file');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
/*query the database*/
//$query = "SELECT fname, lname, info FROM customers WHERE fname LIKE '%$searchterm%'";
$query = "select * from file where $selectfromlist like '%".$searchterm."%'";
$result = $dbconn->query($query);
/*number of rows found*/
$num_results = $result->num_rows;
?>
</br>
<table border="1" width="100%" style="background-color: #ECE5B6;" align="center" BORDERCOLOR=indigo>
<tr bordercolor=red>
<th>Sr. no</th>
<th>Auther First Name</th>
<th>Auther Last Name</th>
<th>Topic Title</th>
<th>Created Date</th>
<th>Download Here</th>
</tr>
<?php
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
$num_found = $i + 1;
$row = $result->fetch_assoc();
//###############################################################################################################################################
echo "
<tr>
<td width=100px>$num_found.</td>
</hr>
<td width=300px>".($row['auther_first_name'])."</td>
<td width=400px>".($row['auther_last_name'])."</td>
<td width=400px>".($row['topic_title'])."</td>
<td width=500px>".($row['created'])."</td>
<td width=600px><a href='get_file.php?id={$row['id']}'>Download</a></td>
</tr>
";
}
?>
</table>
<?php
echo '<p>Result Found : '.$num_results.'</p>';
/*free database*/
$result->free();
$dbconn->close();
?>
</body>
</html>
Comment