如何将数组从经典的ASP发送到PHP页面中的表?
我做的ASP页面的SQL查询,并得到一个100行数据的7列。如何将数组从经典的ASP发送到PHP页面中的表?
例如,我在我的网址或我提交的POST形式的查询字符串读/ GET,
我得到了这一点:“myexample.com/order.php?month=2012-03
”,我使用了“2012-03”作为我的价值ASP页面运行查询“SELECT * FROM CustomerSalesOrder WHERE date LIKE '2012-03%'
”
现在,如上所述,我得到了100行,其中有7列数据关于我的客户在3月购买了什么。
如何将这些数据转换成一个数组,并传递给一个PHP页面生成的表格数据显示表?我知道我可以在1种网页编程语言中运行所有东西,但在ASP页面中运行查询的步骤已经修复,不能更改;而且在PHP页面上显示数据的步骤也是固定的。位于myexample.com,而PHP页面位于mywork.com)
请指引我的一步一步的:
- 转储我的数据到ASP页阵列,并且
- 如何通过我的数据(以阵列形式)到PHP页以适当格式的表形式
我期望专家引导我将数据转换成阵列中ASP,并且阵列的传递给PHP页面的步骤显示数据。
然后,在PHP页面,如何每一个数据爆炸的数组或数据分配给值变量? (我想需要使用循环,在这种情况下,任何循环方法都是最好的?)一旦我以循环或其他方式得到值,然后再循环到表中。
可能,我建议你的ASP页面输出SQL数据的“阵列”为XML,以及PHP页面只是读取XML(使用curl)并解析XML到一个PHP数组?
对外输出SQL数据的XML:
''#### Build SQL Query to grab data as XML (you may want to put this in a stored procedure
dim SqlStr
SqlStr = "SELECT CONVERT(VARCHAR(MAX), (SELECT [ColA] AS 'A', [ColB] AS 'B', [ColC] AS 'C', [ColD] AS 'D', [ColE] AS 'E', [ColF] AS 'F', [ColG] AS 'G'" & _
" FROM CustomerSalesOrder " & _
" WHERE [Date] LIKE '2012-03%' " & _
" FOR " & _
" XML PATH('R') , " & _
" ROOT('ROOT') " & _
" )) as XML"
set rs = db.execute(SqlStr)
do while not rs.eof
XmlStr = rs("XML")
rs.movenext
loop
''#### XML Headers
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Response.ContentType = "text/xml"
Response.Write "<?xml version='1.0' encoding='utf-8'?>"
Response.Write XmlStr
PHP页面可以阅读如下:
$URL = "URL to the ASP page";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
$output = trim(curl_exec($ch));
$xml = simplexml_load_string($output);
//#### Prep Array
var $TargetArray[];
$ArrayPointer = 0;
//#### Parse XML
foreach($xml->children() as $child) {
$ColA = trim($child->A);
$ColB = trim($child->B);
$ColC = trim($child->C);
$ColD = trim($child->D);
$ColE = trim($child->E);
$ColF = trim($child->F);
$ColG = trim($child->G);
//#### Push values into your array (This may be buggy, my php & multi dimensional arrays is a tad rusty)
$row = array('ColA' => $ColA, 'ColB' => $ColB, 'ColC' => $ColC, 'ColD' => $ColD, 'ColE' => $ColE, 'ColF' => $ColF, 'ColG' => $ColG);
$TargetArray[$ArrayPointer] = $data;
$ArrayPointer++;
}
或者,如果你只是想喷卷曲XML转换为HTML表格,你可以做到这一点如下:
//#### Parse XML from CURL into HTML Table
echo "<table>";
echo "<tr>";
echo " <th>ColA</th>";
echo " <th>ColB</th>";
echo " <th>ColC</th>";
echo " <th>ColD</th>";
echo " <th>ColE</th>";
echo " <th>ColF</th>";
echo " <th>ColG</th>";
echo "</tr>";
foreach($xml->children() as $child) {
echo "<tr>";
echo " <th>" . trim($child->A) . "</th>";
echo " <th>" . trim($child->B) . "</th>";
echo " <th>" . trim($child->C) . "</th>";
echo " <th>" . trim($child->D) . "</th>";
echo " <th>" . trim($child->E) . "</th>";
echo " <th>" . trim($child->F) . "</th>";
echo " <th>" . trim($child->G) . "</th>";
echo "</tr>";
}
echo "</table>";
我相信这将需要一些调整,但它应该是eno呃让你去与两个PHP & ASP方面。
你可以这样做那样:
在你的ASP页面,你可以添加一个条件,如果json
参数存在您显示来自查询作为JSON(JSON代码而已,没有HTML)的数据。
在从ASP页面PHP页面显示的数据:
$aspData = json_decode(file_get_contents('http://myexample.com/order.php?month=2012-03&json=1'), true);
echo "<table>";
foreach($aspData as $row){
echo "<tr>";
foreach($row as $colName => $colVal){
echo "<td>$colVal</td>";
}
echo "</tr>";
}
echo "</table>";
我不知道ASP,但应该有功能数组转换为JSON字符串。
对于ASP代码,你应该确保'Response.Codepage'是65001。 – AnthonyWJones 2012-03-02 12:40:45