-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage1_2.php
194 lines (132 loc) · 4.03 KB
/
page1_2.php
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/********************************************************************
* GET A COMPLETE TABLE FROM A [SELECT * FROM table] QUERY
*
* REMARK: adapted for MSSQL Server
*
* notes:
* This function returns an array of arrays. Every array contained
* inside de main array is a associative array representing a table
* row from a MySQL database.
*
*******************************************************************/
function get_table( $result )
{
$index = 0;
$a = array();
while ( $row = sqlsrv_fetch_array( $result/*, SQLSRV_FETCH_ASSOC*/ ) ) {
$a[$index] = $row;
$index++;
}
return $a;
}
/* Specify the server and connection string attributes. */
$serverName = "s-sql.hansbuch.local";
$connectionInfo = array( "UID"=>"HSS", "PWD"=>"HSSintegration", "Database"=>"");
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
################################ SALES TABLE ##########
$tsql = "SELECT CREATEDATE,SALESNUMBER,IMOnumber,CUSTOMERREF,REQUISNUMBER,SALESNAME,DEBTORACCOUNT
FROM SalesTable WHERE DELMODE='OBS' ORDER BY CREATEDATE DESC";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
$sales_table = array();
$sales_table = get_table( $stmt );
//( count($sales_table) - 1 )
######## test test test test ########
/*
for ( $i = 0; $i <= 14; $i++ ) {
$name = $sales_table[$i][5];
$tsql = "SELECT ACCOUNTNUMBER, NAME FROM DebTable WHERE NAME='$name'";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array( $stmt );
$sales_table[$i][6] = $row['0'];
}
*/
######## test test test test ########
echo "<br/><br/>";
echo "SALES TABLE:<br/>";
// table header
$fields = array("CREATEDATE","SALESNUMBER","IMOnumber","CUSTOMERREF","REQUISNUMBER","SALESNAME","DEBTORACCOUNT");
echo "<table border=\"1\"> <tr>";
for ( $i = 0; $i<= (sizeof($fields) - 1); $i++ ) {
echo "<th>".$fields[$i]."</th>";
}
echo "</tr>";
// table body
for ( $row_numb = 0; $row_numb <= 14; $row_numb++ ) {
echo "<tr>";
// print data into table cells
for ( $f = 0; $f <= (sizeof($fields) - 1); $f++ ) {
echo "<td>";
// format datetime fields to be presented as strings
if ( $f == 0 ) {
$toPrint = date_format( $sales_table[$row_numb][$f], "m-d-Y" );
} else {
$toPrint = $sales_table[$row_numb][$f];
}
echo $toPrint;
echo "</td>";
}
echo "</tr>";
}
// table end
echo "</table>";
echo "<br/>";
################################ DEB TABLE ##########
/*
$name = $sales_table[$row_numb - 4][5];
$tsql = "SELECT ACCOUNTNUMBER, NAME
FROM DebTable WHERE NAME='$name'";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
echo "<br/><br/>";
echo "DEB TABLE:<br/>";
// table header
$fields = array("ACCOUNTNUMBER", "NAME");
echo "<table border=\"1\"> <tr>";
for ( $i = 0; $i<= (sizeof($fields) - 1); $i++ ) {
echo "<th>".$fields[$i]."</th>";
}
echo "</tr>";
// table body
for ( $i = 0; $i <= 14; $i++ ) {
//while ( $row = sqlsrv_fetch_array($stmt) ) {
$row = sqlsrv_fetch_array($stmt);
echo "<tr>";
// print data into table cells
for ( $f = 0; $f <= (sizeof($fields) - 1); $f++ ) {
echo "<td>";
echo $row[$fields[$f]];
echo "</td>";
}
echo "</tr>";
}
// table end
echo "</table>";
echo "<br/>";
*/
########################################################
echo "© - High Sea Support Panama - 2008.";
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>