`
hcmfys
  • 浏览: 349559 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

php 连接数据库

    博客分类:
  • php
阅读更多

使用php smart 编写php 比较清晰的代码流程

 

<?
$link=mysql_connect("localhost","root","123456") or die("conenction error");
mysql_select_db("mysql",$link);
$result=mysql_query("show tables ",$link);
$couts= mysql_num_fields($result);
/*
while($row=mysql_fetch_row($result)){
 echo $row[0] ,"<br/>";
}
*/
$arrList =array();
$index=0;

while($row=mysql_fetch_array($result))
{
 //echo $row->Tables_in_mysql ;
 //echo "<br/>";
 $arrList[$index]=$row;
 $index++;
}
mysql_close($link);
//echo $couts;
require 'libs/Smarty.class.php';

$smarty = new Smarty();

$smarty->template_dir="theme/html";
$smarty->compile_dir="theme/cache";
$smarty->assign("userTable",$arrList);
$smarty->assign("age",100);
$smarty->display('table.html'); 
?>

 

下面是  显示页面   感觉和 .net 的很相似了

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>dbTest </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>
{literal}
	<script language="javascript">
 	<!--
 	function isblank(field) {
 	if (field.value == '') {
	   return false;
	}else{
 	  document.loginform.submit();
 	 return true;
 	  }
   }
 	// -->

	</script>
{/literal}

 <body>
  userList
  <ul>
 {foreach from=$userTable item=curUser}
	 <li>{$curUser[0]}</li>
 {/foreach}
  </ul>
  {if $age>10 }
  大于10
  {else}
   小于10
  {/if}
  </body>
</html>

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics