Jump to content

OUTPUT NOT DISPLAYING


dardime

Recommended Posts

Hi I need help to display my search results. The sql code works on SQL Query but it wont display on the page. Any help would be great. Thanks in advance.

 

SQL Query: SELECT * FROM tbrepair WHERE dtSDate>='2016/04/01' AND dtSDate<='2016/04/02'

 

Here is my code

<?php require_once('localhost.php'); 
session_start();

include_once("includes/paging.class.php");
$page = new paging();

$page->db();
$page->table = "tbrepair";			

if(!empty($_POST)) {
	$start_date = $_POST["start_date"];
    $end_date = $_POST["end_date"];
	//$start_date = strtotime($_POST["month_from"]." ".$_POST["day_from"].", ".$_POST["year_from"]);
	//$end_date = strtotime($_POST["month_to"]." ".$_POST["day_to"].", ".$_POST["year_to"]);
	
	$page->cond = "dtSDate>='".$start_date."' AND dtSDate<='".$end_date."'";
	$page->selectQuery();
	$sales = $page->fetchQuery();
}
else {
	if(isset($_GET["page"]) && !empty($_GET["page"])) {
		$current_page = intval($_GET["page"]);	
	}
	else
		$current_page = 1;
		
	$page->page = $current_page;
	
	
	$page->page_limit = 10;
	$page->generateSelectQuery();
	$page->generatePaging();
	$sales = $page->page_results;
}
?>

Here is the form and pagination

<form method="post">
                <td align="right"><strong>Start Date</strong></td>
                <td align="left">
                        <input type="text" class="ui-date" name="start_date" id="start_date" placeholder="Start Date" value="<?php if(!empty($_POST["start_date"]) && !empty($error)) { echo $_POST["start_date"]; } ?>">
                       
                </td>
                <td align="left"><strong>End Date</strong></td>
                <td align="right">
                    <input type="text" class="ui-date" name="end_date" id="end_date" placeholder="End Date" value="<?php if(!empty($_POST["end_date"]) && !empty($error)) { echo $_POST["end_date"]; } ?>">
                    
                </td>
                
          <input type="submit" name="Submit" value="Search" class="medium button">
    </form>
        </div>
  <table width="960" height="52" border="0" align="left" cellpadding="0" cellspacing="0" class="admin applicants">
            <tr class="table-top-bg">
              <th width="19%" height="26" scope="col"><div align="center">DATE</div></th>
              <th width="22%" scope="col"><div align="center">JOB NO</div></th>
          </tr>
            <?php
			if(!empty($sales)) {
				foreach($sales as $sale) {
			?>
            <tr>
              <td width="19%" height="26" scope="col"><div align="center"><?php echo date("F d, Y",$sale["dtSDate"]); ?></div></td>
              <td width="22%" scope="col"><div align="center"><?php echo $sale["cJN"]; ?></div></td>
          </tr>

	    <?php
         }                                               
        }
          else 
             {
       ?>
        <div style="padding-bottom:20px; padding-left:20px;">No records found. Please try again.</div>
        <?php
             }
         ?>  
        </table>
      <?php
        	if(empty($_POST)) { 
        ?>
          <div class="link-fonts" style="clear:both; margin:13px 21px 0px 0px; float:right; font-weight:bold;">
          <?php
			$url = "manage-sales.php";	
			if($page->page <= 1)
				$start = '';
			else
				$start = '<a href="'.$url.'?page=1" class="listViewPaginationLinkS1">Start</a>';

			//prev
			if($page->page <= 1)		
				$prev = '';
			else 
				$prev = '<a href="'.$url.'?page='.$page->page_details["prev"].'" class="listViewPaginationLinkS1">Previous</a>';

			//label
			$label = '<span class="pageNumbers">'.$page->page_details["start"].'  -  '.$page->page_details["to"].'  of  '.$page->page_details["total"].'</span>';

			//next
			if($page->page >= $page->page_details["last"])		
				$next = '';
			else 
				$next = '<a href="'.$url.'?page='.$page->page_details["next"].'" class="listViewPaginationLinkS1">Next</a>';

			//end			
			if($page->page >= $page->page_details["last"])		
				$end = '';
			else 
				$end = '<a href="'.$url.'?page='.$page->page_details["last"].'" class="listViewPaginationLinkS1">End</a>';

			echo $start.'   '.$prev.'   '.$label.'   '.$next.'   '.$end;

			$page->mysqlClose();
		  }
		?>
        </div>

Thank you in advance for your help.

 

Link to comment
Share on other sites

since you didn't share what result you are actually getting, we have no idea which of the many possible things could be wrong. what output did you get and if it's not obvious from looking at it what's wrong with it, tell us what the output should have been.

 

next, we have no idea what the paging class code is, so we have no idea if you are using it correctly. however, it would seem that calling methods like $page->selectQuery(); and $sales = $page->fetchQuery();, before you have set up the paging information is probably wrong.

 

edit: also, processing the form's start_date and end_data values is not mutually exclusive from processing the pagination page number. you should not have the pagination logic, in the first section of code, inside of that particular else {} statement. you should not be putting external data directly into the sql query statement. if this paging class doesn't support using prepared queries, you will need to validate that any external data is exactly and only of the expected format and use the escape string function, from whatever php database extension this paging classing is using, on the data before putting it into the sql query statement.

 

lastly, your form should use method='get', since the dates are determining what will be gotten/displayed on the page. the pagination links should also include any existing $_GET data, so that things like the start_date and end_data will be propagated between page requests. the easiest way of building links is to use http_build_query() for the query-string part of the link.

Edited by mac_gyver
Link to comment
Share on other sites

How about that. I thought the date/time functions only worked on a datetime column. Learned something new today. I would like to know if there is some instance where having the date in that format in varchar will not work with some functions. Must be some reason for the date column type.

Edited by benanamen
Link to comment
Share on other sites

there's nothing in the query that's using any date/time functions, on a column or otherwise. the LITERAL date value (a string in this case) that's being supplied in/to the sql query statement (as part of the sql syntax or via a prepared query parameter) is evaluated by the database engine and converted into a DATE value for the comparison.

 

 

 

You can specify DATETIME, DATE, and TIMESTAMP values using any of a common set of formats: 

 
As a string in either 'YYYY-MM-DD HH:MM:SS' or 'YY-MM-DD HH:MM:SS' format. A “relaxed” syntax is allowed: Any punctuation character may be used as the delimiter between date parts or time parts. For example, '98-12-31 11:30:45', '98.12.31 11+30+45', '98/12/31 11*30*45', and '98@12@31 11^30^45' are equivalent. 
 
As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A “relaxed” syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent. 
 
As a string with no delimiters in either 'YYYYMMDDHHMMSS' or 'YYMMDDHHMMSS' format, provided that the string makes sense as a date. For example, '20070523091528' and '070523091528' are interpreted as '2007-05-23 09:15:28', but '071122129015' is illegal (it has a nonsensical minute part) and becomes '0000-00-00 00:00:00'. 
 
As a string with no delimiters in either 'YYYYMMDD' or 'YYMMDD' format, provided that the string makes sense as a date. For example, '20070523' and '070523' are interpreted as '2007-05-23', but '071332' is illegal (it has nonsensical month and day parts) and becomes '0000-00-00'. 
 
As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided that the number makes sense as a date. For example, 19830905132800 and 830905132800 are interpreted as '1983-09-05 13:28:00'. 
 
As a number in either YYYYMMDD or YYMMDD format, provided that the number makes sense as a date. For example, 19830905 and 830905 are interpreted as '1983-09-05'. 
 
As the result of a function that returns a value that is acceptable in a DATETIME, DATE, or TIMESTAMP context, such as NOW() or CURRENT_DATE. 
 
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.