Create a new database test Execute the following statement (create a new table test: three fields of id, sex and name)
CREATE TABLE `test` ( `id` INT( 4 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `sex` INT( 1 ) NOT NULL , `name` VARCHAR( 20 ) NOT NULL ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin;
Add data to the test table, for example: 1 1 Xiaoqiang 2 0 Xiaohong 3 0 Xiaoli 4 1 Xiaobing 5 1 Zhang San 6 0 Li Si 7 0 Wu Xin Write PHP statement (index.php):
Browse index.php Page, as shown in the picture: It’s time to say byebye, it’s really easy to use!
PHP simple paging function Written a simple PHP paging function, and the database calls are also written in it. People who use it can delete it by themselves!
Copy code The code is as follows:
function getask(){ $sql = "select * from cms_ask where ansower <> ' ' "; //这里要改成方法 $q_sq = mysql_query($sql); $count = mysql_num_rows($q_sq); $page_size = 8; $page_current = isset($GLOBALS['page']) ? intval($GLOBALS['page']) : 1; $page_count = ceil($count / $page_size); $page_start = $page_current - 4; $page_end = $page_current + 4; if ($page_current < 5) { $page_start = 1; $page_end = 5; } if ($page_current > $page_count - 4) { $page_start = $page_count - 8; $page_end = $page_count; } if ($page_start < 1) $page_start = 1; if ($page_end > $page_count) $page_end = $page_count; $pagebar = ""; $sql = "select * from cms_ask where ansower <> ' ' order by id desc limit " . (($page_current - 1) * $page_size) . "," . $page_size; $row=$this -> user -> getall("$sql"); foreach($row as $v){ echo '
http://www.bkjia.com/PHPjc/322617.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322617.htmlTechArticle准备数据: 新建一个数据库 test 执行下面的语句(新建一个表 test :id、sex、name 三个字段) CREATE TABLE `test` ( `id` INT( 4 ) NOT NULL AUTO_INCREMEN...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn