用php+mysql一個名片庫程式_php基礎

來源:互聯網
上載者:User
用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:lyjrich@sina.com,這個程式有個問題如果要顯示全部名片的話,我這個程式還沒有實現此功能,如果你知道在這個程式裡怎樣顯示全部名片的話希望能發mail給我。  

【本文著作權歸作者與奧索網共同擁有,如需轉載,請註明作者及出處】    
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.