Home  >  Article  >  Backend Development  >  The efficacy, functions and consumption methods of American ginseng tablets. Comparison of several methods of displaying data.

The efficacy, functions and consumption methods of American ginseng tablets. Comparison of several methods of displaying data.

WBOY
WBOYOriginal
2016-07-29 08:34:341096browse

When used to display database data, a loop body is generally used. Commonly used methods include while() and for() statements. Let’s talk about their usage in different situations.
Let’s introduce them separately:
The while() statement can display all data, which is especially convenient when the number of loops is unknown. The for() statement can output and display data starting from the specified position to the specified position. , which is useful when outputting and displaying data within a certain range. Let’s take a look at a programming example:
 We first create a database for backup: database name: mydb and table name: tbl.
Use the following statement: create table tal (idx int(3),url char (100), freetext char(100))
You can use the phpmyadmin tool to insert several data into the database table.
Start programming:
$id=mysql_connect("localhost") or die("Unable to establish database link");#Link database
$result=mysql_db_query("mydb","select * from tbl",$id);# Query the results and store them in variables
$rows=mysql_num_rows($result);#Get the total number of rows in the data table, which is the total number of data
echo "

";#Prepare to output in table form
echo "
";#End of table
Insert output statements in the above two sentences. Corresponding to different situations, the output statements are divided into several situations:
If all data is output, use for() first.
for($i=0;$i<$rows;$i++){
$total=mysql_fetch_array($result);
echo "$total[freetext]$total[idx]";
                                                                                                                                         ($total=mysql_fetch_array($result))
{ echo "$total[freetext] $total[idx]";
}
When we want to display it in pages, that is, we cannot display all the data at once, then You can use for() to accomplish this task.
We assume that every time 10 data are output, $page is used to represent the current page number. $pagesize=10 is used to represent the number of data on page. The statement is as follows:
for ($i=0;$i<$pagesize;$ i++)
{
$start=($page-1)*$pagesize+$i;#Count the starting number of data rows
if ($start<$rows)
$idx=mysql_result($result,$start," idx");
$url=mysql_result($result,$start,"url");
$freetext=mysql_result($result,$start,"freetext");
echo "$freetext$idx";
The above statements use for() to obtain the data table respectively The values ​​of each field in are stored in variables and displayed using the echo statement.
The above program runs in apache+mysql+php4
[The copyright of this article is jointly owned by the author and Aosuo.com. If you need to reprint, please indicate the author and source]

The above introduces the efficacy and function of American ginseng tablets and how to consume them. A comparison of several methods of displaying data, including the efficacy and role of American ginseng tablets and how to consume them. I hope it will be helpful to friends who are interested in PHP tutorials.

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