Advertisement

05.29.2008 at 09:45AM PDT, ID: 23442070
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Getting Default Dates In Text Fields

Asked by macrolific in PHP and Databases, PHP Scripting Language, MySQL Server

Tags:

The PHP script below enables me to view a table in my MySQL database.  It allows me to manipulate the data in the following ways:

1) Choose, with checkboxes, which of the 4 columns I want to view,
2) Sort by column from a drop-down menu, and
3) Limit the number of rows by inputing starting and ending dates into text fields.

Number 3, line 66 in the code below, is the one I need help with.  These text fields use a PHP function called strtotime, which parses many textual date formats.  They are coded to retain the inputted dates after the form is submitted and the page comes back.

My only problem now is that when the page first appears, before any viewing criteria has been set, the FROM and TO text fields are empty.  The table is also empty, because no dates have yet been entered.

What I would like is for the text fields to contain default dates when the page first appears.  For example, I'd like the FROM date to be "1/05/08", and the TO date to be "1/06/08".

Can anyone figure out how to do this?  Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
<?php
 
$DB_SERVER=""; // specify IP or domain of your db server
$DB_USERNAME="";
$DB_PASSWORD="";
$DB_NAME=""; // specify name of your database
 
//set the default state for the checkboxes
$checkedFields = array();
$checkedFields['invoice_num'] = " checked='checked' ";
$checkedFields['firstname'] = " checked='checked' ";
$checkedFields['lastname'] = " checked='checked' ";
$checkedFields['transaction_date'] = " checked='checked' ";
 
if( isset($_REQUEST['fieldTracker']) )
{
	//determine the "unchecked" ones 
	if( empty($_REQUEST['invoice_num']) )
		$checkedFields['invoice_num']="";
	if( empty($_REQUEST['firstname']) )
		$checkedFields['firstname']="";
	if( empty($_REQUEST['lastname']) )
		$checkedFields['lastname']="";
	if( empty($_REQUEST['transaction_date']) )
		$checkedFields['transaction_date']="";
}
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<div align="center">
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="select" id="select">
    <input type="checkbox" name="invoice_num" value="1" <?php echo $checkedFields['invoice_num']?>>Invoice
    <input type="checkbox" name="firstname" value="1" <?php echo $checkedFields['firstname']?>>First Name
    <input type="checkbox" name="lastname" value="1" <?php echo $checkedFields['lastname']?>>Last Name
    <input type="checkbox" name="transaction_date" value="1" <?php echo $checkedFields['transaction_date']?>>Date <br>
    Sort By
    <select name="Orderby" id="Orderby">
      <option value="invoice_num"<?php if(isset($_REQUEST['Orderby']) && $_REQUEST['Orderby'] == 'invoice_num') : ?> selected="selected"<?php endif; ?>>Invoice Number</option>
      <option value="firstname"<?php if(isset($_REQUEST['Orderby']) && $_REQUEST['Orderby'] == 'firstname') : ?> selected="selected"<?php endif; ?>>First Name</option>
      <option value="lastname"<?php if(isset($_REQUEST['Orderby']) && $_REQUEST['Orderby'] == 'lastname') : ?> selected="selected"<?php endif; ?>>Last Name</option>
      <option value="transaction_date"<?php if(isset($_REQUEST['Orderby']) && $_REQUEST['Orderby'] == 'transaction_date') : ?> selected="selected"<?php endif; ?>>Date</option>
    </select>
    <br>
From: <input name="date_start" value="<?php echo isset($_REQUEST['date_start']) ? $_REQUEST['date_start'] : ''; ?>">
To: <input name="date_end" value="<?php echo isset($_REQUEST['date_end']) ? $_REQUEST['date_end'] : ''; ?>"><br>
    <input name="fieldTracker" type="submit" value="submit">
  </form>
</div>
<?php
 
if ( !($link = mysql_connect($DB_SERVER, $DB_USERNAME, $DB_PASSWORD)) ) {
    echo 'Could not connect to mysql: ' . mysql_error();
    exit;
}
if (!mysql_select_db($DB_NAME, $link)) {
    echo 'Could not select database: ' . mysql_error();
    exit;
}
$sql = 'SELECT * FROM tbl_authnet_data';
      $sql = $sql . " WHERE transaction_date < '" . date('Y-m-d H:i:s' , strtotime($_POST['date_end'])) . "' AND transaction_date > '" . date('Y-m-d H:i:s' , strtotime($_POST['date_start'])) . "'";
 
if (isset($_REQUEST['Orderby']))
{
      $sql = $sql . " Order By ". $_REQUEST['Orderby'];
}
$result = mysql_query($sql, $link) or die("Query Error: " . mysql_error());
 
if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
$colspan=0;
print "<table align='center' border='0' cellpadding='2' bgcolor='#CCCCCC'>";
print "<tr style='color: white;'>";
if( !empty($checkedFields['invoice_num']) )
{
	++$colspan;
	print "<th>Invoice</th>";
}
if( !empty($checkedFields['firstname']) )
{
	++$colspan;
	print "<th>1st Name</th>";
}
if( !empty($checkedFields['lastname']) )
{
	++$colspan;
	print "<th>Last Name</th>";
}
if( !empty($checkedFields['transaction_date']) )
{
	++$colspan;
	print "<th>Date</th>";
}
 
print "</tr>";
print "<tr><td colspan='{$colspan}'></td></tr>";
 
// Define colors for alternating rows
$color1 = "#fffaf0";
$color2 = "#ffffff";
$row_count = 0;
 
while ($row = mysql_fetch_assoc($result))
{
	$row_color = ($row_count % 2) ? $color1 : $color2;
		print "<tr>";
		foreach ($row as $field => $value)
		{
		if( isset($checkedFields[$field]) && !empty($checkedFields[$field]) )
           	print "<td nowrap='nowrap' align='center' bgcolor='{$row_color}'>{$value}</td>";
		}
		print "</tr>";
		$row_count++;
}
print "</table>";
 
?>
</body>
</html>
 
Loading Advertisement...
 
[+][-]05.29.2008 at 09:55AM PDT, ID: 21670991

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:03AM PDT, ID: 21671061

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:09AM PDT, ID: 21671113

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language, MySQL Server
Tags: PHP, MySQL
Sign Up Now!
Solution Provided By: SuprSpy79
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.29.2008 at 06:59PM PDT, ID: 21674738

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 07:01PM PDT, ID: 21674746

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628