打印本文 打印本文  关闭窗口 关闭窗口
用php+mysql一个名片库程序
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 14:36:19
用php+mysql一个名片库程序,有分类查找,分页功能。

第一步:按下列代表先做个静态页面。
<form method="post" action="find1.php" name="card" onSubmit="return card_Validator(this)">
          <table width="400" border="0" cellspacing="0" cellpadding="0" class="p10">
            <tr>  
              <td colspan="2" height="79">  
                <table width="280" border="0" cellspacing="0" cellpadding="0" class="p10">
                  <tr>  
                    <td colspan="3" height="37">输入关键字:
<input type="text" name="keyword" class="c3a">
                    </td>
                  </tr>
                  <tr>  
                    <td>  
                      <input type="radio" name="inout" value="N" checked>
                      按姓名</td>
                    <td>  
                      <input type="radio" name="inout" value="C">
                      按地区</td>
                    <td>  
                      <input type="radio" name="inout" value="A">
                      按职位</td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>  
              <td colspan="2" height="47">  
                <input type="submit" name="query1" value="查找">
                <input type="reset" name="Submit2" value="清除">
              </td>
            </tr>
          </table>
        </form>
第二步:如下建库。
id  int(4)    否    auto_increment   
http  varchar(25)    否
name  varchar(50)    否       
email  varchar(50)    否       
gs  varchar(200)    否       
address  varchar(200)    否        
yb  varchar(20)    否       
zw  varchar(100)    否       
tel  varchar(20)    否       
fax  varchar(20)    否       
bp  varchar(20)    否       

第三步:查找执行程序
<?php

if (!isset($show)) $show=0;

{   




if($query1=="查找")

{

$db=mysql_connect("localhost","用户名","密码");
$dbname=mysql_select_db("库文件名",$db);
mysql_query('select * from 表文件名',$db);
$limit=2; //一页显示几条内容。

//global $query,$queryyy,$quer;
switch($inout)

{
   
   case "N":  
  //按姓名查找
$query="select * from card where name like '%$keyword%'";  
    
  
$queryyy = "select * from card where name like '%$keyword%' order by id desc limit $show, $limit";    
   
   break;
    
   case "C":
   //按地区查找
$query="select * from card where address like '%$keyword%' order by id desc";  
    
    $queryyy = "select * from card where address like '%$keyword%' order by id desc limit $show, $limit";         
   break;
    
   case "A":  
  // 按职务查找
   $query="select * from card where zw like '%$keyword%' order by id desc";  
    
  $queryyy = "select * from card where zw like '%$keyword%' order by id desc limit $show, $limit";    
   break;
    
   }
$result1=mysql_query($query);  
$total=mysql_num_rows($result1); //总的符合条件的记录数  

$quer=mysql_query($queryyy,$db);
$pages=ceil($total/$limit);
  }
  }

?>
   
  <p><font color="#FF0000" face="宋体" size="3"><strong><span style="font-size: 12pt"><font size="4" color="#000000">你查找的关键字是:</font></span></strong></font>:<font color=red><? echo $keyword;?></font></p>
                    
        
<?  




echo "<table width='400' border='0' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td width='314'>
      <div align='center'>查找名片如下: 共有[<font color=red>";
      echo $total;
       echo "</font>]张名片</div>
    </td>
    <td width='86'>
      <div align='right'>共分[<font color=red>";
      echo $pages;
       
     echo "</font>]页 </div>
    </td>
  </tr>
</table>";

while ($row = mysql_fetch_array($quer))
{

echo "<table width='440' border='1' cellspacing='0' cellpadding='0' height='175' align='center' bordercolordark='#eeeeee' bordercolorlight='#666666'>    
  
<tr>
    <td>
      <table width='380' border='0' cellspacing='0' cellpadding='0' align='center' bgcolor='#eeeeee'>
        <tr>  
          <td colspan='2' height='53'>  
            <div align='center' class='pp13'><font color='#000000'>$row[gs]</font></div>
        

[1] [2]  下一页



打印本文 打印本文  关闭窗口 关闭窗口