WinNT下PHP访问ODBC的例程-数据库查询
这是一个有三个字段的简单数据库,用来记录一个导航站的数据信息,实际运行的例子在http://web.hnpts.ha.cn/navg
SQL Server数据库:
表daohang
url char(255) 记录的网址
name char(255) 网站名称
type int   网站分类

------------------------------


<html>
<head>
<title>邮校导航站检索</title>
<meta http-equiv="目录类型" content="文本/html; 字符集=gb2312">
<style type="text/css">
<!--
a {  font-size: 9pt; text-decoration: none}
a:hover {  font-size: 9pt; color: #CCCCFF; text-decoration: underline overline}
.unnamed1 {  font-size: 9pt}
-->
</style>
</head>

<body bgcolor="#FFFFFF" background="bj37.jpg" text="#FFFFFF" link="#99FFFF" vlink="#99FFFF" alink="#99FFFF">
<table width="100%" border="0" cellspacing="0">
  <tr>
    <td width="507" valign="top"> 
      <div align="center"><img src="dh.gif" width="42" height="42"> <b><font size="6"><i>河南邮校网络导航站</i></font></b> 
        <br>
        <font color="#33FF33"><b><br>
        带你到天涯 带你到海角<br>
        </b></font></div>
    </td>
    <td width="306"><img src="tit.gif" width="300" height="100"></td>
  </tr>
</table>
<?
  $tit
=array(1=>"河南电信站点","河南社会站点","国内电信站点","国内知名站点","国内大专院校","国外站点");
  
$ds=odbc_connect("***","***","***");
  
$sql="select * from daohang where name like '%".$name."%'";
  
$rs=odbc_do($ds,$sql);
?>  
<table width="795" border="0" cellspacing="0" height="395">
  <tr> 
    <td width="144" valign="top" align="left" class="unnamed1"> <?for ($i=1;$i<=6;$i++) { ?> 
      <img src="bb.gif" width="21" height="15">
                <? print("<a href=index.php?tpe=".$i.">".$tit[$i]."</a>");?> 
      <br>
      <? ?><br>
      <br>
      <font color="#33FF33"><center><img src="http://www.hnpts.ha.cn/count/count.php?user=daohang&bit=9"></center></font> 
        <form method="post" action="chaxun.php">
              <font color="#9933FF"><b>搜索引擎<br>
              </b></font>关键词: 
              <input type="text" name="name" maxlength="20" size=8>
              <input type="submit" name="Submit" value="查询">
            </form>  
    </td>
    <td width="647" valign="top">
<center>
        <br>
        <br>
        <table width="70%" border="1" cellspacing="0">
          <tr>
            <td><center>
                <?print($name);?><br>
                <br>
              </center>
             <table width=100% >
           <?$i=0;
             while (
odbc_fetch_into($rs,&$res))
               {print(
"<tr>"); 
                
$url=$res[0];$name=$res[1];$tpe=$res[2];
                print (
"<td align=center><a href=http://".$url.">".$name."</a>");
                print(
"<td class=unnamed1 align=center>".$tit[$tpe]);
                
$i++;
                print(
"</tr>");
                  }
              
?>