How to break search about pages (a paginal conclusion of the data)?
What is the breakdown on pages? The most simple example - search machines. You give the command on search in reply to what the server gives out thousand links (and the other information such as the name of page, date, and so forth). But there is a given information not on one page. She is broken into parts. In this example you nauchitet` to break result of search on a database into pieces, that organizirovat` postarnichnyj a conclusion.
Let's create a file default.phtml which contains base fukncii. You should correct parameters (host/user/pass/base)
<?
// A global variable. For example, it is necessary in function of a connection.
$sock=false;
// New functions
function sql ($a) {return mysql_query ($a);}
function sqlrows ($a) {return @mysql_num_rows ($a);}
function sqlval ($a, $b, $c) {return @mysql_result (mysql_query ($a), $b, $c);}
function sqlget ($a) {return @mysql_fetch_array ($a);}
function sqlline ($a) {return sqlget (sql ($a));}
function sqllast () {return mysql_insert_id ();}
// A connection to the server
function connect () {
global $sock;
$host = "**";
$user = "**";
$base = "**";
$pass = "**";
$sock = mysql_connect ($host, $user, $pass);
if (! $sock ||! @mysql_select_db ($base, $sock))
die (" the Server temporarily does not work ");
unset ($host);
unset ($user);
unset ($base);
unset ($pass);
}
// Replacement die ()
function xdie ($zapros = "", $info = "") {
die (" </table> </table> </table> </table> <hr> <h3> ************ $info *********** <br> <br>
sql error..... n " .mysql_errno (). ":" .mysql_error (). " </h3> <pre> $zapros </pre> <hr> ");
}
?>
The given file (create.phtml) will create the table limit_test and will hammer in it{her} in 500 lines
Kind from different lines.
<?
include ("./default.phtml");
connect ();
// We delete the table (just in case)
sql (" drop table limit_test ");
// We create
if (! sql (" create table limit_test (id int, s char (100)) "))
xdie ("", the Table is not created ");
srand (time ());
// We create search of a kind <<... values (x, "xx"), (y, "yy")... (z, "zz")>>
$s = " insert into limit_test values ";
for ($i=0; $i <500; $i ++) {
$s. = " ($ i, " ";
$x=rand (1,100);
for ($j=0; $j <$x; $j ++) $s. = chr (rand (ord ('a'), ord ('z')));
$s. = "") ";
if ($i+1 <500) $s. = ",";
}
// We carry out search to fill the table with the data
if (! sql ($s)) xdie ($s, " the Table is not filled ");
?>
Actually, a file (search.phtml) which displays the form for search and
Deduces the found results on?? Pieces on page.
<body bgcolor=black text=white link = * 9999cc vlink = * cc9999> <font face=arial>
<?
include ("./default.phtml");
if (! isset ($z)) $z = "";
if (isset ($all)) $all=intval ($all);
if (isset ($start)) $start=intval ($start);
if (isset ($len)) $len=intval ($len);
else $len=10;
echo " <form action = " http: // phpclub.chat.ru/mysql / % 24php_self " method=get>
<input type=hidden name=z value=search>
That we search:
<input type=text name=s value = ' $ s'>
Lines:
<input type=text name=len value = ' $ len ' size=5>
*nbsp; <input type=submit value = 'search'> <br> <br>
Spec. Symbols:
<font color = * ff6666> <b> <big> _ </big> </b> </font> - replaces 1 any letter,
<font color = * ff6666> <b> <big> % </big> </b> </font> - replaces any sequence of letters.
Search ' <b> % </b> ' - will find all the line long, search ' <b> _ </b> ' - only lines,
Consisting of 1 symbol. If to look 'a', most likely, anything
It will not be found, however lines ' %a % ' precisely will be. <br>
</form> ";
switch ($z) {
case "search":
connect ();
$query = " select s from limit_test where s like ' $s' ";
if (! isset ($start)) {
if (! ($res=sql ($query))) xdie ($query, "mistake");
$start=0;
$all=sqlrows ($res);
} else {
$query. = " limit $start, $len ";
if (! ($res=sql ($query))) xdie ($query, "mistake");
}
echo " Search: <font color = * 00ff00> $query </font> <br> <br> ";
for ($j=1; $j <= $len ** $tmp=sqlget ($res); $j ++) {
echo ($start + $ j). ". $tmp [s] <br> ";
$stop-;
}
echo "<br>";
for ($i=1; $i <=floor ($all / $ len); $i ++)
echo " <a href = "../../tppmsgs/msgs0.htm*123 " tppabs = " http: // phpclub.chat.ru/mysql / % 24php_self? z=search*all = $ all*len = $ len and ". "
" start = ". (($i-1) * $len). " *s = ".urlencode ($s.) "> $i </a> ";
break;
}
?>

|