php 页面之间传值实例教程
传值方法很多,
参数传值: 可以是urs.php?id=1带参数形式,这是页面之间比较主要的传值方式 ,用request,get 接收值.
from表单传值 : 主要接收request传值 post, get 来接收,from标签可以选择get或者post 通过url传值的是get 还可以利用ajax传值可以选择post或者get.
session传值 : 这个一般是做用户登陆时用的,服务器全局变量,一般不用在页面之前的传值
cookie传值 :把内容保存在客户端,
我们常用的页面传值主要是参数传值 from表单传值传值。
现在来做几个实例
*/
//先用页面参数传值实例
?>
<a href="b.php?action=1">点击我</a>
//输出值为 1
用form传值
<form action="b.php" method="get">
<input name="action" type="text" value="5">
<input type="submit" value="submit" />
</form>
得出值 5
<form action="b.php" method="POST">
<input name="action" type="text" value="5">
<input type="submit" value="submit" />
</form>
<?
if( $_GET )
{
echo 'get传值',$_GET['action'];
}
else
{
echo 'post传值', $_POST['action'];
}
//本文章原创于www.111cn.net 中国WEB第一站,,转载注明出处
<?php教程
class resizeimage
{
//图片类型
var $type;
//实际宽度
var $width;
//实际高度
var $height;
//改变后的宽度
var $resize_width;
//改变后的高度
var $resize_height;
//是否裁图
var $cut;
//源图象
var $srcimg;
//目标图象地址
var $dstimg;
//临时创建的图象
var $im;
function resizeimage($img, $wid, $hei,$c,$dstpath)
{
$this->srcimg = $img;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
//图片的类型
$this->type = strtolower(substr(strrchr($this->srcimg,"."),1));
//初始化图象
$this->initi_img();
//目标图象地址
$this -> dst_img($dstpath);
//--
$this->width = imagesx($this->im);
$this->height = imagesy($this->im);
//生成图象
$this->newimg();
ImageDestroy ($this->im);
}
function newimg()
{
//改变后的图象的比例
$resize_ratio = ($this->resize_width)/($this->resize_height);
//实际图象的比例
$ratio = ($this->width)/($this->height);
if(($this->cut)=="1")
//裁图
{
if($ratio>=$resize_ratio)
//高度优先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
if($ratio<$resize_ratio)
//宽度优先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
ImageJpeg ($newimg,$this->dstimg);
}
}
else
//不裁图
{
if($ratio>=$resize_ratio)
{
$newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
if($ratio<$resize_ratio)
{
$newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
}
}
//初始化图象
function initi_img()
{
if($this->type=="jpg")
{
$this->im = imagecreatefromjpeg($this->srcimg);
}
if($this->type=="gif")
{
$this->im = imagecreatefromgif($this->srcimg);
}
if($this->type=="png")
{
$this->im = imagecreatefrompng($this->srcimg);
}
}
//图象目标地址
function dst_img($dstpath)
{
$full_length = strlen($this->srcimg);
$type_length = strlen($this->type);
$name_length = $full_length-$type_length;
$name = substr($this->srcimg,0,$name_length-1);
$this->dstimg = $dstpath;
//echo $this->dstimg;
}
}
$resizeimage = new resizeimage("1.jpg", "200", "150", "1","2.jpg");
?>
if( $_POST )
{
$str = '23=12,34 78=1,3 45=12,46,78,89=33';
$content=nl2br($str);
$content=str_replace(" ","",$content);
$arr=explode("<br/>",$content);
$result=array();
foreach ($arr as $value)
{
$k=explode("=",$value);
$result[]=array($k[0]=>$k[1]);
}
//数组转换成字串
function arrayeval($array, $level = 0) {
$space = '';
for($i = 0; $i <= $level; $i++) {
$space .= " ";
}
$evaluate = "Array $space( ";
$comma = $space;
foreach($array as $key => $val) {
$key = is_string($key) ? '''.addcslashes($key, ''\').''' : $key;
$val = !is_array($val) && (!preg_match("/^-?d+$/", $val) || strlen($val) > 12 || substr($val, 0, 1)=='0') ? '''.addcslashes($val, ''\').''' : $val;
if(is_array($val)) {
$evaluate .= "$comma$key => ".arrayeval($val, $level + 1);
} else {
$evaluate .= "$comma$key => $val";
}
$comma = ", $space";
}
$evaluate .= " $space)";
return $evaluate;
}
//把结果写到文件
$config=arrayeval($result);
$strwrite="<?php ".'$'.'shuzu'.'='.$config." ?>";
$fp=fopen('config.php','w');
fwrite($fp,$strwrite);
fclose($fp);
}
?>
<form action="b.php?action=5" method="get">
<textarea name="content"></textarea>
<input type="submit" value="submit" />
</form>
缓存的工作原理其实并不复杂。它的核心思想是:首先,我们将需要显示的内容存储在一个文本文件(即缓存文件)之中。然后,如果有用户请求某个页面的内容,我们首先检查此页对应的缓存(即那个文本文件)是否存在——如果存在且为最新的缓存文件,那么直接将这个文本文件中的内容输出到客户端供用户查看;如果此页对应的缓存文件不存在或缓存生成的时间不符合要求(太旧),那么直接执行一次此页对应的PHP文件,并将显示内容存储在缓存文件中。重复上述流程。这样一来,虽然增加了PHP代码,但我们最大程度的节省了PHP链接到数据库教程再提取数据的时间。
*/
//导入缓存类
require_once('cache.class.php教程');
//创建一个缓存类对象CacheManager
$CacheManager = new Cache();
//调用startCache方法,表示开始缓存
$CacheManager->startCache();
//以下区块所有echo内容都将作为缓存写入缓存文件中
echo "Start Cache example at: ".date('H:i:s')."<br/>";
sleep(2);
echo "End Cache example at: ".date('H:i:s')."<br/>";
echo "<br/><a href='clear.php'>Clean the cache</a><br/>";
//以上区块所有echo内容都将作为缓存写入缓存文件中
$CacheManager->endCache();
//cache.class.php代码
class Cache {
var $status = true; // 值为True表示开启缓存;值False表示关闭缓存功能。
var $cacheDir = 'cache/'; //存放缓存文件的默认目录
var $cacheFile = ''; //缓存文件的真实文件名
var $timeOut = 1000; // 内容被重复使用的最长时限
var $startTime = 0; // 程序执行的开始时间
var $caching = true; // 是否需要对内容进行缓存;值为False表示直接读取缓存文件内容
function getMicroTime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function startCache(){
$this->startTime = $this->getMicroTime();
ob_start();
if ($this->status){
$this->cacheFile = $this->cacheDir.urlencode( $_SERVER['REQUEST_URI'] );
if ( (file_exists($this->cacheFile)) &&
((fileatime($this->cacheFile) + $this->timeOut) > time()) )
{
//从缓存文件中读取内容
$handle = fopen($this->cacheFile , "r");
$html = fread($handle,filesize($this->cacheFile));
fclose($handle);
// 显示内容
echo $html;
// 显示程序执行时间
echo '<p>Total time: '
.round(($this->getMicroTime())-($this->startTime),4).'</p>';
//退出程序
exit();
}
else
{
//置缓存标志caching为true
$this->caching = true;
}
}
}
function endCache(){
if ($this->status){
if ( $this->caching )
{
//首先输出页面内容,然后将输出内容保存在缓存文件中
$html = ob_get_clean();
echo $html;
$handle = fopen($this->cacheFile, 'w' );
fwrite ($handle, $html );
fclose ($handle);
//显示页面执行时间
echo '<p>Total time: '.round(($this->getMicroTime()-$this->startTime),4).'</p>';
}
}
}
function cleanCache(){
if ($handle = opendir($this->cacheDir)) {
while (false !== ($file = readdir($handle))) {
if (is_file($this->cacheDir.$file)) unlink($this->cacheDir.$file);
}
closedir($handle);
}
}
}
// 再一个简单的php 缓存文件实例代码
if ($content = $cache->start($cache_id))
{
echo $content;
exit();
}
require_once 'Cache/Function.php';
$cacheDir = './pear_cache/';
$cache = new Cache_Function('file',array('cache_dir' => $cacheDir));
$arr = array('东方', '南方','西方');
$cache->call('slowFunction', $arr);
echo '<BR>';
$arr = array('东方', '南方','西方');
slowFunction($arr);
function slowFunction($arr = null)
{
echo "一个执行起来很慢的函数 :( <br>";
echo "当前时间是 " . date('M-d-Y H:i:s A', time()) . '<br>';
foreach ($arr as $fruit)
{
echo "太阳此时正在 $fruit <br>";
}
)
述前说明:
CREATE VIEW 语句时,ANSI_NULLS 和 QUOTED_IDENTIFIER 选项必须设置为 ON。OBJECTPROPERTY 函数通过 ExecIsAnsiNullsOn 或 ExecIsQuotedIdentOn 属性为视图报告此信息
表a,字段a1,a2
表b,字段b1,b2
要弄个视图union all两个表
$sql ='CREATE VIEW dbo.VIEW2
AS
SELECT * FROM a
UNION ALL
(SELECT * FROM b )';
上面的是简单的创建视图并没有索引下面我们来看看关于创建索引视图
对指定表或指定表的视图创建关系索引。可在向表中填入数据前创建索引。可通过指定限定的数据库教程名称对另一个数据库中的表或视图创建关系索引。
语法:
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON <object> ( column_name [ ASC | DESC ] [ ,...n ] )
[ WITH <backward_compatible_index_option> [ ,...n ] ]
[ ON { filegroup_name | "default" } ]
<object> ::=
{
[ database_name. [ owner_name ] . | owner_name. ]
table_or_view_name
}
<backward_compatible_index_option> ::=
{
PAD_INDEX
| FILLFACTOR = fillfactor
| SORT_IN_TEMPDB
| IGNORE_DUP_KEY
| STATISTICS_NORECOMPUTE
| DROP_EXISTING
}
//--创建视图
create view v
with schemabinding
as
select ID,name from dbo.A
go
// --创建索引
create unique clustered index v_index on v(ID)
相关文章
- 今天小编在这里就来给Painter的这一款软件的使用者们来说一说绘制红衣喝酒男水粉画效果的教程,各位想知道具体绘制步骤的使用者,那么下面就快来跟着小编一起看一看教程...2016-09-14
iPhone6怎么激活?两种苹果iPhone6激活教程图文详解
iPhone6新机需要激活后才可以正常使用,那么对于小白用户来说,iPhone6如何激活使用呢?针对此问题,本文就为大家分别介绍Wifi无线网络激活以及iPhone6连接电脑激活这两种有效的方法,希望本文能够帮助到大家...2022-09-14- 今天小编在这里就来给各位photoshop的这一款软件的使用者们来说下制作雨中野外孤独行走的一头牛海报的教程,各位想知道具体制作方法的使用者们,大家就快来看一看小编给...2016-09-14
- 今天小编在这里就来给Painter的这一款软件的使用者们来说一下绘制帅气卡通魔法王子漫画的具体教程,各位想知道绘制步骤的使用者,那么下面就快来跟着小编一起看一看教程...2016-09-14
- 今天小编在这里就来给各位Illustrator的这一款软件的使用者们来说说鼠绘堆雪人的孩童矢量插画的教程,各位想知道具体绘制方法的使用者们,那么各位就快来跟着小编来看看...2016-09-14
- 支付宝支付在国内算是大家了,我们到处都可以使用支付宝了,下文整理介绍的是在安卓app应用中使用支付宝进行支付的开发例子。 之前讲了一篇博客关与支付宝集成获取...2016-09-20
- 今天小编在这里就来给美图秀秀的这一款软件的使用者们来说下究竟该怎么给照片天空加蓝天白云的教程,各位想知道具体制作步骤的,那么下面就来跟着小编一起看看吧。 ...2016-09-14
- 今天小编在这里就来给llustrator的这一款软件的使用者们来说一说绘制扁平化风格卡通警察护士空姐肖像的教程,各位想知道具体绘制步骤的使用者们,那么下面就快来跟着小编...2016-09-14
- 今天小编在这里就来给Illustrator的这一款软件的使用者们来说一下绘制一个方形的录音机图标的教程,各位想知道具体绘制方法的使用者们,那么下面就来看一下小编给大家分...2016-09-14
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说一说简单制作一个搞笑的换脸表情包的教程,各位想知道具体制作方法的使用者们,那么大家就快来看一看教程吧。...2016-09-14
- 今天小编在这里就来给各位photoshop的这一款软件的使用者们来说说给手绘画调色变换场景的后期教程,各位想知道具体后期处理步骤的使用者们,那么大家就快来跟着小编来看...2016-10-02
- 今天小编在这里就来给美图秀秀的这一款软件的使用者们来说一下让你胸丰满起来的处理教程,各位想知道具体处理步骤的,那么下面就快来跟着小编一起看一下教程吧。 给...2016-09-14
- 今天小编在这里就来给Painter的这一款软件的使用者们来说一下绘制雷神传插画的教程,各位想知道具体绘制步骤的使用者,那么下面就快来跟着小编一起看看绘制方法吧。 ...2016-09-14
PHP传值到不同页面的三种常见方式及php和html之间传值问题
在项目开发中经常见到不同页面之间传值在web工作中,本篇文章给大家列出了三种常见的方式。接触PHP也有几个月了,本文总结一下这段日子中,在编程过程里常用的3种不同页面传值方法,希望可以给大家参考。有什么意见也希望大...2015-11-24- 今天小编在这里就来给美图秀秀的这一款软件的使用者们来说下制作隔离区聊天背景的教程,各位想知道具体方法的,那么下面就快来跟着小编一起看一看吧。 给各位美图秀...2016-09-14
- 联合索引又叫复合索引。对于复合索引:Mysql从左到右的使用索引中的字段,一个查询可以只使用索引中的一部份,但只能是最左侧部分。例如索引是key index (a,b,c). 可以支持a | a,b| a,b,c 3种组合进行查找,但不支持 b,c进...2015-11-24
- 这篇文章主要给大家介绍的是关于Lua语言新手入门的简单教程,文中通过示例代码一步步介绍的非常详细,对各位新手们的入门提供了一个很方便的教程,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。...2020-06-30
- 直接为大家介绍制作过程,希望大家可以喜欢。HTML结构该页面切换特效的HTML结构使用一个<main>元素来作为页面的包裹元素,div.cd-cover-layer用于制作页面切换时的遮罩层,div.cd-loading-bar是进行ajax加载时的loading进...2015-10-30
- 一、下载 mysqlsla [root@localhost tmp]# wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz--19:45:45-- http://hackmysql.com/scripts/mysqlsla-2.03.tar.gzResolving hackmysql.com... 64.13.232.157Conn...2015-11-24
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说说用素材合成古典园林场景教程,各位想知道到底该怎么制作的,那么就快来一起看一下吧。 给各位photoshop...2016-09-14