程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 用php+mysql一個名片庫程序

用php+mysql一個名片庫程序

編輯:關於PHP編程

用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>
          </td>
        </tr>
        <tr>  
          <td height='35' colspan='2' align=center>  
     <b class='pp13'>$row[name] <span class='pp9'>$row[zw] <br>
              </span></b>
              <hr color='#FFCC00' noshade size='1'>

          </td>
        </tr>
        <tr>  
          <td colspan='2'>  
            <ul>
              <li><span class='pp10'>電話:$row[tel]</span></li>
              <li><span class='pp10'>傳真:$row[fax]</span></li>
              <li><span class='pp10'>網址:$row[http]</span></li>
              <li><span class='pp10'>電子信箱:$row[eamil]</span></li>
              <li><span class='pp10'>地址:$row[address]</span></li>
              <li><span class='pp10'>郵編:$row[yb]</span></li>
              <li><span class='pp10'>BP:$row[bp]</span></li>
            </ul>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </table><br>";

        
}

$vor = $show + $limit;
$back = $show - $limit;
print "<center>";

print "<table width="455" border="0" bordercolor="#FFCC33" cellspacing="0" align="center" >";
print "<tr  height="20" bgcolor="#FFD6AC"><td width="350" >";
for ($i=1;$i<=$pages;$i++)
{
    $new_offset=$limit*($i-1);
    $parameter="query1=$query1&keyword=$keyword&inout=$inout";

     

     
    print "<a href="$PHP_SELF?show=$i&$parameter"><b> $i</b></a>$nbsp";
}
print "</td><td width="45" >";
//顯示上一頁
if ($show - $limit >= 0)
{
print " <a href="$PHP_SELF?show=$back&$parameter">上一頁</a>";
}
print "</td><td width="45">";
//顯示下一頁
if (($show + $limit) < $total)
{
print "<a href="$PHP_SELF?show=$vor&$parameter">下一頁</a> ";
}
print "</td><td width="60">";
//顯示全部留言
//print "<a href="$PHP_SELF?show=all.&$parameter">全部名片</a> ";
print "</td></tr></table>";
print "</center>";
?>
若有問題請mailto:[email protected],這個程序有個問題如果要顯示全部名片的話,我這個程序還沒有實現此功能,如果你知道在這個程序裡怎樣顯示全部名片的話希望能發mail給我。  

【本文版權歸作者與奧索網共同擁有,如需轉載,請注明作者及出處】    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved