当前位置:  编程技术>php
本页文章导读:
    ▪php,不用COM,生成excel文件       用php生成excel文件  <?header("Content-type:application/vnd.ms-excel");header("Content-Disposition:filename=test.xls");echo "test1\t";echo "test2\t\n";echo "test1\t";echo "test2\t\n";echo "test1\t";echo "test2\t\n";echo "test1\t";echo "test.........
    ▪PHP中GET变量的使用           自PHP4.1.0以后将HTTP_GET_VARS使用GET变量来保存,GET的变量主要来自以下的方法对服务器以获取资料信息为请求方法的例如,URL,使用FORM的METHOD为GET方式。这样所有的请求变量将通过URL传.........
    ▪一个ORACLE分页程序,挺实用的.       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD><TITLE>Paging Test</TITLE><META NAME="Generator" CONTENT="TextPad 4.0"><META NAME="Author" CONTENT="?"><META NAME="Keywords" CONTENT="?"&.........

[1]php,不用COM,生成excel文件
    来源: 互联网  发布时间: 2013-11-30
用php生成excel文件  

<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>
  在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到最终的结果,怎么样不错吧。
  其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头用header("Content-type:application/vnd.ms-excel");表示输出的是excel文件,用header("Content-Disposition:filename=test.xls");表示输出的文件名为text.xls。这样就ok了。



  我们更可以修改header让他输出更多格式的文件,这样php在处理各种类型文件方面就更加方便了.

    
[2]PHP中GET变量的使用
    来源: 互联网  发布时间: 2013-11-30
    自PHP4.1.0以后将HTTP_GET_VARS使用GET变量来保存,GET的变量主要来自以下的方法

对服务器以获取资料信息为请求方法的例如,URL,使用FORM的METHOD为GET方式。这样所有的请求变量将通过

URL传递给服务器,服务器根据配置调用相关的解释器来处理这些GET出来的变量。

  

    本文针对URL 的GET方式传值进行讨论

    我们都知道URL传值为URL?变量名=变量值

      这个方式进行递交请求例如

    http://www.bbs.bbc.com?page=1

    这样的方法为我们现在所通用

    如果变量多了可以使用'&'符号连接变量

    例如: http://www.bbs.bbc.com?page=1&title=Welcome%20Sports98

    以上方法为浏览器直接将变量转变到相对应的数组中,我们并不需要去过多的了解。下面为我所要讨论的话题


    例如:

        http://www.bbs.bbc.com?page=1,Welcome%20Sports98,Sports98,300


        这个例子说明的是,我们使用','这个符号为变量分隔符号,这里我们可以用两种方法来实现,
一、修改PHP.INI

——
; List of separator(s) used by PHP to parse input URLs into variables.
; Default is "&".
; NOTE: Every character in this directive is considered as separator!
arg_separator.input = ";,"
————

二、自己编写解释语法

        list($key,$value)=$_GET;    //将GET变量分解出来
        $tmp=explode(",",$value);    //将数据分出

    这个用法的优点在于,别人无法知道您传递的值是被谁使用,您自己需要明白各个值的使用

    ++++++++++++++++++++++++++++++++++++++


    最后针对
        http://www.bbs.bbc.com/index.php?123,123433,234524,34563456,5463,78685,abc,Welcome%20Sports98

    这一类的GET方法的传值,其实方法与方法二相同,需要的是将KEY转换成VALUE进行分解,我觉得这个方法比上一个方法要好

    而且更加方便.
        $value=key($_GET);
        $tmp=explode(",",$value);

    你应该都已经获得到这些数据了。


    以上方法为本人浏览其他站点所看到现象所想到的方法,不知是否正确。对于PHP的默认安装用户都喜欢使用默认的GET传值方式

    如果是公司有特定要求的可以考虑使用后面的方法~

                        学有所限,如有不对还请指正.


                                    Sports98 Write by 2002-8-16

    
[3]一个ORACLE分页程序,挺实用的.
    来源: 互联网  发布时间: 2013-11-30
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Paging Test</TITLE>
<META NAME="Generator" CONTENT="TextPad 4.0">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php

// How to split the result into pages, like 'limits' in MySQL?
// ===========================================================
// Tutorial by Neil Craig (neilc@netactive.co.za)
// Date: 2001-06-05
// With this example, I will explain paging of database queries where the
// result is more than the developer want to print to the page, but wish to
// split the result into seperate pages.
// The table "SAMPLE_TABLE" accessed in this tutorial has 4 fields:
// PK_ID, FIELD1, FIELD2 and FIELD3. The types don't matter but you should
// define a primary key on the PK_ID field.

$display_rows = 5;     // The rows that should be display at a time. You can
                       // modify this if you like.

// Connect to the Oracle database
putenv("ORACLE_SID=purk");
putenv("ORACLE_HOME=/export/oracle8i");
putenv("TNS_ADMIN=$ORACLE_HOME/network/admin");
$OracleDBConn = OCILogon("purk","purk","lengana.world");

// This query counts the records
$sql_count = "SELECT COUNT(*) FROM SAMPLE_TABLE";

// Parse the SQL string & execute it
$row_count=OCIParse($OracleDBConn, $sql_count);       
OCIExecute($row_count);

// From the parsed & executed query, we get the amount of records found.
// I'm not storing this result into a session variable because it allows for
// new records to be shown as it is entered by another user while the result
// is printed.
if (OCIFetch($row_count)) {
    $num_rows = OCIResult($row_count,1);
} else {
    $num_rows = 0;        // If no record was found
}

// Free the resources that were used for this query
OCIFreeStatement($row_count);

// We need to prepare the query that will print the results as a page. I will
// explain the query to you in detail.

// If no page was specified in the url (ex. http://mysite.com/result.php?page=2),
// set it to page 1.
if (empty($page) || $page == 0) {
    $page = 1;
}

// The start range from where the results should be printed
$start_range = (($page - 1) * $display_rows) + 1;

// The end range to where the results should be printed
$end_range = $page * $display_rows;

// The main query. It consists of 3 "SELECT" statements nested into each
// other. The center query is the query you would normally use to return the
// records you want. Do you ordering and "WHERE" clauses in this statement.
// We select the rows to limit our results but because the row numbers are
// assigned to the rows before any ordering is done, lets the code print the
// result unsorted.
// The second nested "SELECTED" assigns the new row numbers to the result
// for us to select from.

$sql = "SELECT PK_ID, FIELD1, FIELD2, FIELD3, ROW_NO FROM (SELECT PK_ID, ";
$sql .= "FIELD1, FIELD2, FIELD3, ROWNUM ROW_NO FROM (SELECT PK_ID, FIELD1, ";
$sql .= "FIELD2, FIELD3 FROM SAMPLE_TABLE ORDER BY FIELD3)) WHERE ROW_NO BETWEEN ";
$sql .= $start_range." AND ".$end_range;

// start results formatting
echo "<table width='95%' border='1' cellspacing='1' cellpadding='2' align='center'>";
echo "<tr bgcolor='#666666'>";
echo "<td><b><font color='#FFFFFF'>PK ID</font></b></td>";
echo "<td><b><font color='#FFFFFF'>Field 1</font></b></td>";
echo "<td><b><font color='#FFFFFF'>Field 2</font></b></td>";
echo "<td><b><font color='#FFFFFF'>Field 3</font></b></td>";
echo "<td><b><font color='#FFFFFF'>Row No</font></b></td>";
echo "</tr>";

if ($num_rows != 0) {

    // Parse the SQL string & execute it
    $rs=OCIParse($OracleDBConn, $sql);       
    OCIExecute($rs);

    // get number of columns for use later
    $num_columns = OCINumCols($rs);

    while (OCIFetch($rs)){
        echo "<tr>";
        for ($i = 1; $i < ($num_columns + 1); $i++) {
            $column_value = OCIResult($rs,$i);
            echo "<TD>$column_value</TD>";
        }
        echo "</tr>";
    }

} else {

    // Print a message stating that no records was found
    echo "<tr><td align=center>Sorry! No records was found</td></tr>";
}

// Close the table
echo "</TABLE>";

// free resources and close connection
OCIFreeStatement($rs);
OCILogoff($OracleDBConn);

?>
<div align=center>
<?php

// Here we will print the links to the other pages

// Calculating the amount of pages
if ($num_rows % $display_rows == 0) {
    $total_pages = $num_rows / $display_rows;
} else {
    $total_pages = ($num_rows / $display_rows) + 1;
    settype($total_pages, integer); // Rounding the variable
}

// If this is not the first page print a link to the previous page
if ($page != 1) {
    echo "<a href='".$PHP_SELF."?page=".($page - 1)."'>Previous</a>";
}

// Now we can print the links to the other pages
for ($i = 1; $i <= $total_pages;  $i++) {
    if ($page == $i){
        // Don't print the link to the current page
        echo " ".$i;
    } else {
        //Print the links to the other pages
        echo " <a href='".$PHP_SELF."?page=".$i."'>".$i."</a>";
    }
}

// If this is not the last page print a link to the next page
if ($page < $total_pages) {
    echo " <a href='".$PHP_SELF."?page=".($page + 1)."'>Next</a>";
}

?>
</div>
<?php

// I'm just adding this section to print some of the variables for extra info
// and some debugging

echo "<p><b>Total pages: </b>".$total_pages."</p>";
echo "<p><b>Number of records: </b>".$num_rows."</p>";
echo "<p><b>The SQL Query is:</b> ".$sql."</p>";

?>
</BODY>
</HTML>

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪php数组长度的获取方法(三个实例) iis7站长之家
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3