Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Need Guide for Search with date and paging page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Need Guide for Search with date and paging page

Postby html807 » Sat Nov 24, 2012 2:06 am

hi guys ..im newbie need help how to create php search with date filter.
below is my code and still no luck to work ..., if just the txtbox for search some word in database thats work ..but ineed add to filter by date range .. how can i achieve this ...

thanks before...

Image

Code: Select all
/******** end form search*******/

<?php
$from=isset($_REQUEST["date3"]) ? $_REQUEST["date3"] : "";
$to=isset($_REQUEST["date4"]) ? $_REQUEST["date4"] : "";
$single=isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : "";

echo "start from&nbsp;".$from."&nbsp;to&nbsp;".$to."<br>";
echo $single;
?>
</td>
<td valign="top">

<table class="ewTable ewTableSeparate">
<?php

//************search by text***************************************
if(isset($_GET["btnsubmit"])) {

$where ="";
if($_GET['txtKeyword']!="") {
$s[] = "`custPost` like '%" . mysql_real_escape_string($_GET['txtKeyword']) . "%'";
}

/*
if(!($single=="0000-00-00")) {
$s[] = "`datePost`='%" . mysql_real_escape_string($single) . "%'";
}
*/

if(!($from=="0000-00-00") || ($to="0000-00-00")) {

$s[] = "`datePost`>='$from' AND `datePost`<='$to'";
}

if(isset($s)){
$where = "WHERE (" . implode(" AND ",$s).")";
}

$sql="SELECT * FROM datapost {$where}";
echo $sql;
//exit();

$batas=5;
$query=mysql_query($sql);
$data=mysql_num_rows($query);
$jumhal=ceil($data/$batas);
$page=$_GET["page"];
if(!isset($_GET["page"])){
   $mulai=0;
}else{
   $mulai=$page * $batas;
}

$sql="SELECT * FROM datapost {$where} ORDER BY idPost desc limit $mulai,$batas";
$query=mysql_query($sql);
$pages=$page + 1;

}else {


$sql="SELECT * FROM datapost ORDER BY idPost desc";
echo $sql;
//exit();

$batas=5;
$query=mysql_query($sql);
$data=mysql_num_rows($query);
$jumhal=ceil($data/$batas);
$page=$_GET["page"];
if(!isset($_GET["page"])){
   $mulai=0;
}else{
   $mulai=$page * $batas;
}
$sql="SELECT * FROM datapost ORDER BY idPost desc limit $mulai,$batas";
$query=mysql_query($sql);
$pages=$page + 1;


}

?>
<tr bgcolor="#898991">
<th>No CRM</th>
<th>Nama Nasabah</th>
<th>No Kartu</th>
<th>Permintaan</th>
<th>Status</th>
<th>Remarks</th>
<th>Download</th>
<th>Reply</th>
</tr>
<?php
while($cetak=mysql_fetch_array($query)) {
?>
<tr>
   <td><?php echo $cetak['crmNum'];?></td>
   <td><?php echo $cetak['custPost'];?></td>
    <td><?php echo $cetak['cardPost'];?></td>
    <td><?php echo $cetak['request'];?></td>
    <td><?php echo $cetak['status'];?></td>
    <td><?php echo $cetak['notePost'];?></td>
    <td><a href='../CRMposts/upload/<?php echo $cetak[filePost]?>'><?php echo $cetak[filePost]?></a></td>
    <td><a href='reply.php?ID=<?php echo $cetak['idPost'];?>'><?php echo "Reply";?></a></td>   
</tr>
   <?php } if($_GET["txtKeyword"] != "") { ?>

<tr>
   <td colspan="8">
   <center>
   <a href="indexal.php?page=<?php echo max($page-1,0);?>&txtKeyword=<?php echo $_GET[txtKeyword];?>">Prev</a>
   || Total Record : <b><?php echo $data;?></b> || Total Page : <b><?php echo $jumhal;?></b> || Current Page : <b><?php echo $pages;?></b> ||
   <a href="indexal.php?page=<?php echo min($page+1,$jumhal-1);?>&txtKeyword=<?php echo $_GET[txtKeyword];?>">Next</a>
    </center>
   </td>
</tr>   

   <?php } else{?>
   
<tr>
   <td colspan="8">
   <center>
   <a href="indexal.php?page=<?php echo max($page-1,0);?>">Prev</a>
   || Total Record : <b><?php echo $data;?></b> || Total Page : <b><?php echo $jumhal;?></b> || Current Page : <b><?php echo $pages;?></b> ||
   <a href="indexal.php?page=<?php echo min($page+1,$jumhal-1);?>">Next</a>
    </center>
   </td>
</tr>   

   <?php } ?>
</table>

Attachments
myform.jpg
from for search with somw filter not work ..
myform.jpg (85.89 KiB) Viewed 626 times
html807
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Nov 24, 2012 1:39 am

Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron