新匍京娱乐场下载:php简单的留言板实例程序,php分页程序及简单实例说明

if($_POST[新匍京娱乐场下载,’op’] == ‘edit’) {
    $sql = “
        UPDATE ” . TABLE_PREFIX . “user
        SET
            name = ‘” . $_POST[‘name’] . “‘,
            birthday = ‘” . $_POST[‘birthday’] . “‘,
            email = ‘” . $_POST[新匍京娱乐场下载:php简单的留言板实例程序,php分页程序及简单实例说明。’email’] . “‘,
            sex = ‘” . $_POST[‘sex’] . “‘
        WHERE
            id = ‘” . $_POST[‘id’] . “‘

$sql=”select * from my_note where note_url=’4′”;
 $result=mysql_query($sql) or die(‘Error’.mysql_error());
 $allrecord=mysql_num_rows($result);
 $page=isset($_GET[‘page’])?$_GET[‘page’]:1;
 $pagesize=10;
 $pagecount=($allrecord % $pagesize)?(int)($allrecord / $pagesize)
+1:$allrecord / $pagesize;
 $page=($page>$pagecount || $page<1)?$page=1:$page;
 $start=$pagesize*($page-1);
 $sqllist=”select * from my_note where note_url=’4′  order by id desc
limit $start,$pagesize “;
 $resulte=mysql_query($sqllist) or die(‘Error ‘.mysql_error());
 $num=mysql_num_rows($resulte);
 if($num){
  while($rs=mysql_fetch_object($resulte)){
   if($rs->note_url==’1′){
   echo(“<li><img src=’pic/point.jpg’ /> <a
href='”.$rs->note_content.”‘ class=note
target=’_blank’>”.$rs->note_title.”</a>
[“.$rs->note_date.”] <img src=’pic/new.gif’
/></li>n”);
   }else{
   echo(“<li><img src=’pic/point.jpg’ /> <a
href=’show.php?id=”.$rs->id.”‘ class=note
target=’_blank’>”.$rs->note_title.”</a>
[“.$rs->note_date.”]</li>n”);
   }
  }
 echo(“<div id=’page’><div class=li> 共”.$pagecount.”页
每页”.$pagesize.”条记录 共”.$allrecord.”个作品</div>”);
 for($i=$pagecount;$i>=1;$i–){
  echo(“<div class=li><a
href=?page=”.$i.”>”.($i).”</a></div>”);
 }
  echo(“</div>”);
 }else{
  echo(‘No Infomation’);
 }
}

首先数据库的SQL如下:

本文实例汇报了php轻松smarty入门程序。分享给大家供大家参考。具体如下:

        “;
    if(db_exec($sql)) {
        $notice = array(
            ‘msg’ => ‘修改成功’,
            ‘alt’ => ‘列表顾客’,
            ‘url’ => ‘?op=index’
        );
        require_once ‘view/_notice.phtml’;
    } else {
        $notice = array(
            ‘msg’ => ‘修改失利’,
            ‘alt’ => ‘修改客商’,
            ‘url’ => ‘?op=edit&id=’ . $_POST[‘id’]
        );
        require_once ‘view/_notice.phtml’;
    }
} else {
    $sql = “
        SELECT *
        FROM “. TABLE_PREFIX . “user
        WHERE id = ‘”. (int)$_GET[‘id’] .”‘ “;
    $data = fetch($sql);
    require_once ‘www.111cn.net/edit.phtml’;
}

 代码如下

首先要有3个文本夹configs、templates、templates_c,在configs文件夹中有贰个配备文件:test.conf,代码:

edit.phtml代码

— — 表的组织 `message` —

title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true

<html>
<head>
    <meta http-equiv=”Content-Type” content=”text/html;
charset=utf-8″ />
    <title>客户编辑</title>
</head>
<body>
    <h3>顾客编辑</h3>
    <form action=”?op=edit” method=”post”
enctype=”application/x-www-form-urlencoded”>
        姓名:<input type=”text” name=”name” size=”15″
value=”<?php echo $data[‘name’] ?>” /><br />
        生日:<input type=”text” name=”birthday” size=”10″
value=”<?php echo $data[‘birthday’] ?>” /> (YYYY-MM-DD)<br
/>
        邮箱:<input type=”text” name=”email” size=”30″
value=”<?php echo $data[’email’] ?>” /><br />
        性别:<input type=”radio” name=”sex” value=”3″<?php
if($data[‘sex’] == ‘-‘) : ?> checked=”checked”<?php endif; ?>
/>保密
              <input type=”radio” name=”sex” value=”1″<?php
if($data[‘sex’] == ‘M’) : ?> checked=”checked”<?php endif; ?>
/>男
              <input type=”radio” name=”sex” value=”2″<?php
if($data[‘sex’] == ‘F’) : ?> checked=”checked”<?php endif; ?>
/>女<br />
        <input type=”hidden” name=”id” value=”<?php echo
$data[‘id’] ?>” />
        <input type=”hidden” name=”op” value=”edit” /><br
/>
        <input type=”submit” name=”submit”
value=”编辑顾客www.111cn.net” />
    </form>
    <?php require_once ‘view/_foot.phtml’; ?>
</body>
</html>

CREATE TABLE `message` (   `id` int(10) NOT NULL auto_increment,  
`user` varchar(25) character set utf8 NOT NULL,
`title` varchar(50) character set utf8 NOT NULL,   `content`
tinytext character set utf8 NOT NULL,   `lastdate` date NOT NULL,

templates中有模板文件:test.htm:

PRIMARY KEY  (`id`) ) ENGINE=InnoDB  DEFAULT CHARSET=gbk
AUTO_INCREMENT=11 ;

<html> 
  <head> 
    <title>Smarty Test</title> 
  </head> 
  <body> 
    <H1>Hello, {$Name}</H1> 
  </body> 
</html> 

程序代码如下:

php文件代码:

先是创造config.php,代码如下:

<?php 
require 'libs/Smarty.class.php'; //包含Smarty类库文件 
$smarty = new Smarty; //创建一个新的Smarty对象 
$smarty->assign("Name","Simon"); //对模版中的变量赋值 
$smarty->display('test.htm'); //显示页面 
?>

 代码如下

运行后呈现的页面代码:

<?php $conn = @mysql_connect(“localhost”,”root”,””) or
die(“数据库老是出错!”);
mysql_select_db(“lyb”,$conn);
mysql_query(“set names utf8”); ?>

<html> 
  <head> 
    <title>Smarty Test</title> 
  </head> 
  <body> 
    <H1>Hello, Simon</H1> 
  </body> 
</html> 

接下来创立index.php,代码如下:

运营之后,还在templates_c文件夹中生成四个php文件:

 代码如下

<?php
/* Smarty version 2.6.22, created on 2009-03-19 13:20:00 
     compiled from test.htm */
?> 
<html> 
  <head> 
    <title>Smarty Test</title> 
  </head> 
  <body> 
    <H1>Hello, <?php echo $this->_tpl_vars['Name']; ?> 
</H1> 
  </body> 
</html> 

相关文章