I already solve my query issues now the pagination that I implement together with won't work even if the syntax may look like it will work. i already tried every suggestion of every programmers community but its not doing any changes to the result. Kindly help me because this is the last requirement to me to complete the project. Here is the code:
$fromDate = "2015-01-01";
$toDate = "2015-01-30";
$dept = "PACKING";
$user = "root";
$pass = "admin";
$host = "localhost";
$db = "tempdb";
try{
$cxn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$cxn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$cxn->exec('SET NAMES "utf8"');
}
catch(PDOException $e){
echo "Unable to connect to server" . $e->getMessage();
exit();
}
try{
if(isset($_POST['id']) &&
isset($_POST['empid']) &&
isset($_POST['employee']) &&
isset($_POST['department']))
{
$id = $_POST['id'];
$empid = $_POST['empid'];
$employee = $_POST['employee'];
$department = $_POST['department'];
if($_POST['submit']==0)
{
$query = $cxn->prepare("SELECT emptb.*, tempstore.* FROM (SELECT * FROM
emptb WHERE id < '".$id."' Department = :dept ORDER BY id DESC LIMIT 1)emptb
inner join tempstore
on emptb.EmpID = tempstore.EmpID WHERE tempstore.ValidDate BETWEEN
DATE(:fromDate) AND DATE(:toDate)");
$query->bindParam(':fromDate',$fromDate);
$query->bindParam(':toDate',$toDate);
$query->bindParam(':dept',$dept);
$query->execute();
$s = $query->fetch();
extract($s);
$id = $id;
$empid = $EmpID;
$employee = $Lastname . ", " . $Firstname;
$department = $Department;
}
elseif($_POST['submit']==1)
{
$query = $cxn->prepare("SELECT emptb.*, tempstore.* FROM (SELECT * FROM
emptb WHERE id > '".$id."' Department = :dept ORDER BY id ASC LIMIT 1)emptb
inner join tempstore
on emptb.EmpID = tempstore.EmpID WHERE tempstore.ValidDate BETWEEN
DATE(:fromDate) AND DATE(:toDate)");
$query->bindParam(':fromDate',$fromDate);
$query->bindParam(':toDate',$toDate);
$query->bindParam(':dept',$dept);
$query->execute();
$s = $query->fetch();
extract($s);
$id = $id;
$empid = $EmpID;
$employee = $Lastname . ", " . $Firstname;
$department = $Department;
}
}
else
{
$query = $cxn->prepare("SELECT emptb.*, tempstore.* FROM (SELECT * FROM
emptb WHERE Department = :dept ORDER BY id ASC LIMIT 1)emptb inner join
tempstore
on emptb.EmpID = tempstore.EmpID WHERE tempstore.ValidDate BETWEEN
DATE(:fromDate) AND DATE(:toDate)");
$query->bindParam(':fromDate',$fromDate);
$query->bindParam(':toDate',$toDate);
$query->bindParam(':dept',$dept);
$query->execute();
$s = $query->fetch();
extract($s);
$id = $id;
$empid = $EmpID;
$employee = $Lastname . ", " . $Firstname;
$department = $Department;
}
}
catch(PDOException $e){
echo "Unable to execute query " . $e->getMessage();
exit();
}
echo "<form action='' method='post'><pre>
ID<input type='text' readonly='readonly' value='$empid'>
Employee<input type='text' readonly='readonly' value='$employee'>
Department<input type='text' readonly='readonly' value='$department'>
<button name='submit' value='0'>PREVIOUS</button> <button name='submit'
value='1'>NEXT</button></pre></form>";
echo "<table><tr><th>Date</th><th>TimeIn</th><th>LunchOut</th>
<th>LunchIn</th><th>Timeout</th></tr>";
while($r = $query->fetch())
{
extract($r);
if($TimeIn=="00:00:00"){
$TimeIn="";
}
else{
$TimeIn= date("g:i",strtotime($TimeIn)) . " " . "AM";
}
if($LunchOut=="00:00:00"){
$LunchOut="";
}
else{
$LunchOut= date("g:i",strtotime($LunchOut)) . " " . "nn";
}
if($LunchIn=="00:00:00"){
$LunchIn="";
}
else{
$LunchIn=date("g:i",strtotime($LunchIn)) . " " . "PM";
}
if($TimeOut=="00:00:00"){
$TimeOut="";
}
else{
$TimeOut= date("g:i",strtotime($TimeOut)) . " " . "PM";
}
echo "<tr>
<td>$ValidDate</td>
<td>$TimeIn</td>
<td>$LunchOut</td>
<td>$LunchIn</td>
<td>$TimeOut</td>
</tr>";
}
echo "</table>";
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…