[PHP與MySQL]①③--文章檢索功能

Paste_Image.png

article.search.php

<?php 
    require_once('connect.php');
    $key = $_GET['key'];
    $sql = "select * from article where title like '%$key%' order by dateline desc";
    $query = mysql_query($sql);
    if($query&&mysql_num_rows($query)){
        while($row = mysql_fetch_assoc($query)){
            $data[] = $row;
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文章發布系統</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<!-- start header -->
<div id="header">
    <div id="logo">
        <h1><a href="#">php與mysql<sup></sup></a></h1>
        <h2></h2>
    </div>
    <div id="menu">
        <ul>
            <li class="active"><a href="article.list.php">文章</a></li>
            <li><a href="about.php">關于我們</a></li>
            <li><a href="contact.php">聯系我們</a></li>
        </ul>
    </div>
</div>
<!-- end header -->
</div>

<!-- start page -->
<div id="page">
    <!-- start content -->
    <div id="content">
    <?php
        if(empty($data)){   
            echo "當前沒有文章,請管理員在后臺添加文章";
        }else{
            foreach($data as $value){
    ?>
        <div class="post">
            <h1 class="title"><?php echo $value['title']?><span style="color:#ccc;font-size:14px;">  作者:<!--作者放置到這里--><?php echo $value['author']?></span></h1>
            <div class="entry">
                <?php echo $value['description']?>
            </div>
            <div class="meta">
                <p class="links"><a href="article.show.php?id=<?php echo $value['id']?>" class="more">查看詳細</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;</p>
            </div>
        </div>
    <?php
            }
        }
    ?>
    </div>
    <!-- end content -->
    <!-- start sidebar -->
    <div id="sidebar">
        <ul>
            <li id="search">
                <h2><b class="text1">Search</b></h2>
                <form method="get" action="">
                    <fieldset>
                    <input type="text" id="s" name="s" value="" />
                    <input type="submit" id="x" value="Search" />
                    </fieldset>
                </form>
            </li>
        </ul>
    </div>
    <!-- end sidebar -->
    <div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->
<!-- start footer -->
<div id="footer">
    <p id="legal"></p>
</div>
<!-- end footer -->
</body>
</html>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容