Page 1 of 1

searching through date limit

Posted: Wed May 27, 2009 11:45 am
by azeemaqsood
Hi to all,
I made a post earlier this morning but I dont know was it deleted by a moderator intentionaly or it did get deleted itself. Anyways I believe if this is a forum to help people understand the language then it should entertain all the people.

Any my scenario was; I have php search in which there is an option of 4 radio buttons based search keywords which are
subject, recepient, posted by, designation, text and posted date.

I have to change this date radio button based search to date from-date to based search. How can i do it. The php code is attached. The date of completion of this assignment is 28th of may. Kindly help. The code is as under..

Code: Select all

 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="outer">
    <?php
    include("includes/header.php"); 
    ?> 
    <div id="menu">
        <ul>
        <?php
    include("includes/nav.php"); 
    ?>          </ul>
    </div>
    <div id="content">
        <?php
        include("includes/rightColumn.php");
        ?>
        <div id="primaryContentContainer">
            <div id="primaryContent">
                <h2>Search CIS Mails!</h2>
                <form name="form1" method="get" action="<? echo $_SERVER['PHP_SELF']?>">
                <blockquote>
                 <table>
                 <tr>
                 <td>
                <strong> Keywords:</strong>
                 </td>
                 <td>
                 <input type="text" name="txtsearch" value="<?php echo($_GET['txtsearch']); ?>"> 
                 </td>
                 <td>
                 <input type="submit" name="Submit" value="Go!" class="button">
                 </td>
                 <tr>
                 <td>
                <strong> Search by :</strong>
                 </td>
                 <td colspan="2" height="20" >
                 <table cellspacing="0" cellpadding="0">
                 <tr  class="rowA">
                  <td>
                      
        <input type="radio" name="radiosearch" value="tSubject" <?php if($_GET['radiosearch'] == "tSubject") echo("checked");?> >
  Subject
                  </td>
                  <td>
                    
        <input name="radiosearch" type="radio"  value="tName" <?php if($_GET['radiosearch'] == "tName") echo("checked");?> >
  Recipient
                  </td>
                 </tr>
                 <tr class="rowB" >
                   <td>   
                    
         <input type="radio" name="radiosearch" value="FName" <?php if($_GET['radiosearch'] == "FName") echo("checked");?>>
  Posted by
                  </td>
                  <td>
                  
                        <input type="radio" name="radiosearch" value="FDesignation" <?php if($_GET['radiosearch'] == "FDesignation") echo("checked");?>>
  Designation
                  </td>
                 </tr>
                 <tr class="rowA" >
                   <td>   
        <input type="radio" name="radiosearch" value="bin_data" <?php if($_GET['radiosearch'] == "bin_data") echo("checked");?>>
  Text 
                  </td>
                  <td>
                
<!--<input type="radio" name="radiosearch" value="date" <?php if($_GET['radiosearch'] == "date") echo("checked");?>>
  Posted Date
  (yyyy-mm-dd)-->
   <input type="text" name="radiosearch" value="bin_data" <?php if($_GET['radiosearch'] == "bin_data") echo("checked");?>>
                  </td>
                 </tr>
                 </table>
                 </td>
                 </tr>
                 </table>       
                </blockquote>   
                 </form>
                
 
 
<?php 
// current/max values - set defaults if values aren't set
include("connect2db.php");
$cur=$_GET['cur'];
$max=$_GET['max'];
$radiosearch =  $_GET['radiosearch'];
$txtsearch =$_GET['txtsearch'];
if ($txtsearch) {
    //$query =$_GET['query'];
    if ($cur) 
        $cur = ($cur);
    else
         $cur = 0;
    if ($max) 
        $max = ($max);
    else
         $max = 15;
//$query = "as";
// set query arguments here, so we dont have to duplicate it
 
    $args = " WHERE $radiosearch LIKE '%$txtsearch%'";
 
// build a string of all variables that need to be passed from page to page
    $passthrough = '&max='.$max.'&txtsearch='.$txtsearch;
// run query and echo out results 
    $sql = "SELECT * FROM tbl_files $args LIMIT $cur,$max";
//print ($sql);
    $res = mysql_query($sql);
    $count=0;
  echo "    <table width='100%' align='center'>";
    while ($row = mysql_fetch_array($res)) {
    if($count==0)
    {
    echo "<tr class='rowH'>";
    echo "<th colspan='2'>Search Results</th>";
    echo "</tr>";
    }
    if($count%2==0)
    {
    echo "<tr class='rowA'><td>>></td>";
    echo ("<td width='80%'><a href=\"download.php?id=".$row[id]."\" class='lk'>".$row["tSubject"].'</a></td></tr>');
    }
    else
    {
    echo "<tr class='rowB'><td>>></td>";
    echo ("<td width='80%' ><a href=\"download.php?id=".$row[id]."\" class='lk'>".$row["tSubject"].'</a></td></tr>');
    }
    $count+=1;
    }
   echo "</table>";
// get total, and echo out paging links
 
    $total = mysql_result(mysql_query("SELECT count(*) FROM tbl_files $args"),0);
    $next = ($cur+$max < $total) ? '<a href="search.php?cur='.round($cur+$max).$passthrough.'&radiosearch='.($radiosearch).'">next '.$max.' »</a>' : '<span style="color: #aaaaaa">next '.$max.' »</span>';
    $prev = ($cur-$max >= 0) ? '<a href="search.php?cur='.round($cur-$max).$passthrough.'&radiosearch='.($radiosearch).'">« previous '.$max.' </a>' : '<span style="color: #aaaaaa">« previous '.$max.' </span>';
    if ($total == 0)  
    echo ("<table width='100%' align='center'><tr class='rowH'><th colspan='2'>Record Not exists please Retry</th></tr></table>");
    else if ($total >= 15) {
    echo '<div align="center" style="font: 12px Verdana;"> '.$prev.' - '.$next.'  ('.$total.' total)</div>'; 
    } else
    echo '<div align="center" style="font: 12px Verdana;">('.$total.' total)</div>';
    mysql_close();
}//if 
else echo("<table width='100%' align='center'><tr class='rowH'><th colspan='2'>Plese enter a string in order to search Letter</th></tr></table>");
?>
 
 
            </div>
        </div>
        <?php 
        
        include("includes/leftColumn.php");
        ?>
        <div class="clear"></div>
    </div>
    <?php
    include("includes/footer.php");
    ?>
</div>
</body>
</html>
 


thanks....

Re: searching through date limit

Posted: Wed May 27, 2009 11:56 am
by JKM
Use unix timestamps and strtotime().

And please use

Code: Select all

<code>