还有很多条件没有判断, 我正则不是很会。 写的很粗糙,勉强能用, 希望别介意哈!
<?php
class Database {
public $conn
public function Database() {
$this->conn = mysql_connect("localhost","user","password")
mysql_select_db("gamesearch",$this->conn)
mysql_query("SET NAMES 'UTF8'")
}
public function get_data_array($sql) {
$rs = mysql_query($sql,$this->conn)
$data_array = array()
while($data = mysql_fetch_array($rs,MYSQL_ASSOC)) {
$data_array[] = $data
}
mysql_free_result($rs)
return $data_array
}
}
$db = new Database()
if($_GET['year'] == "") {
echo "请输入年份!"
}else {
if($_GET['year'] == "all") {
$sql = "select GameName from GameSearch"
}else {
$sql = "select GameName from GameSearch where ReleaseYear = ".$_GET['year']
}
$data = $db->get_data_array($sql)
foreach($data as $k=>$v) {
echo $v['GameName']."<br />"
}
}
?>
<form action="test.php" method="get">
年份:<input type="text" name="year" value="all" />
<input type="submit" value="提交" />
</form>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)