Jump to content

Filter Date Range not working!!


Ethan_Hunt
Go to solution Solved by kicken,

Recommended Posts

Hi Mates, the problem that I have is, i want to enter in two text field date and filter the SQL query. after submit the button, i don't receive or see any error after executing!

my db is oracle and my sys date format is like : 08.03.23. based on my assumption, something with my date format is not correct in my code.

<?php
	include 'orc_php.php';
	
	$post_at = "";
	$post_at_to_date = "";
	
	$queryCondition = "";
	if(!empty($_POST["search"]["post_at"])) {			
		$post_at = $_POST["search"]["post_at"];
		list($fid,$fim,$fiy) = explode("-",$post_at);
		
		$post_at_todate = date('Y-m-d');
		if(!empty($_POST["search"]["post_at_to_date"])) {
			$post_at_to_date = $_POST["search"]["post_at_to_date"];
			list($tid,$tim,$tiy) = explode("-",$_POST["search"]["post_at_to_date"]);
			$post_at_todate = "$tiy-$tim-$tid";
		}
		
		$queryCondition .= "and auf.aufdzhost BETWEEN '$fiy-$fim-$fid' AND '" . $post_at_todate . "'";
	}

	$sql = "select distinct
       auf.aufdzhost
     , auf.aufnr
     , te.tenam
     , art.artnr
     , aup.aupmgist
from
       auf_a_v  auf
     , te_a_v   te
     , artall_v art
     , aup_a_v  aup
where
       auf.aufid            = te.aufid
       and aup.aufid        = auf.aufid
       and art.artid        = aup.artid
       and auf.aufGrpNam like 'NATCAN%'
       and aup.aupmgist    != 0 " . $queryCondition . " ORDER BY AUFDZHOST desc";
	$result = oci_parse($conn,$sql);
?>

<<html>
	<head>
    <title>Filter Date</title>		
	<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
	<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

	<style>
	.table-content{border-top:#CCCCCC 4px solid; width:50%;}
	.table-content th {padding:5px 20px; background: #F0F0F0;vertical-align:top;} 
	.table-content td {padding:5px 20px; border-bottom: #F0F0F0 1px solid;vertical-align:top;} 
	</style>
	</head>
	
	<body>
    <div class="demo-content">
		<h2 class="title_with_link">Filter Date</h2>
  <form name="frmSearch" method="post" action="">
	 <p class="search_input">
		<input type="text" placeholder="From Date" id="post_at" name="search[post_at]"  value="<?php echo $post_at; ?>" class="input-control" />
	    <input type="text" placeholder="To Date" id="post_at_to_date" name="search[post_at_to_date]" style="margin-left:10px"  value="<?php echo $post_at_to_date; ?>" class="input-control"  />			 
		<input type="submit" name="go" value="Search" >
	</p>
<?php if(!empty($result))	 { ?>
<table class="table-content">
          <thead>
        <tr>
                      
          <th width="30%"><span>Post Title</span></th>
          <th width="50%"><span>Description</span></th>          
          <th width="20%"><span>Post Date</span></th>	  
        </tr>
      </thead>
    <tbody>
	<?php
		oci_execute($result);
		while($row = oci_fetch_array($result)) {
	?>
        <tr>
			<td><?php echo $row["AUFDZHOST"]; ?></td>
			<td><?php echo $row["ARTNR"]; ?></td>
			<td><?php echo $row["TENAM"]; ?></td>

		</tr>
   <?php
		}
   ?>
   <tbody>
  </table>
<?php } ?>
  </form>
  </div>

If I don't use the text field and directly enter the date in my SQL query in PHP codes, then I get the result. But in fact, I need to filter the form input text in web and not in background.

thank you for your helps.

Ali

Link to comment
Share on other sites

  • Solution
6 minutes ago, Ethan_Hunt said:

my query looks like below when I execute it in SQL Developer.

Did you get that query from your code by echoing out $sql?

echo $sql;
$result = oci_parse($conn,$sql);

The question is whether the query your generating is what you're expecting it to be, so you will want to echo it and verify it.

If you can copy/paste the echo'ed query from the page into sql developer and get results, but get no results in PHP then maybe there is some environment difference or the code for reading the results is problematic.  I've not used oracle so cannot say much about it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.