~ Maybe it's a small doubt

Source: Internet
Author: User
Help ~ It may be a small problem. PHPcode $ query & quot; SELECT * fromnewsORDERbyiddescLimit $ offset, $ page_size & quot; $ resultmysql_query ($ query, $ conn); $ rowmysql_fetch_array ($ result ); $ i0; whil help ~ It may be a small problem
PHP code
  $query="SELECT * from news ORDER by id desc Limit $offset,$page_size";$result=mysql_query($query,$conn);$row=mysql_fetch_array($result);$i=0;while($i<$rows=mysql_num_rows($result)){    $i++;    echo "

"; echo "

"; echo " "; echo " "; echo " "; echo " "; echo " "; } echo "
"; echo "".$row["title"].""; echo ""; echo "[".$row["author"]."]"; echo ""; echo "[".$row["date"]."]"; echo "
";


The result is as follows:
Test4 [aa] [15:36:00]

Test4 [aa] [15:36:00]

Test4 [aa] [15:36:00]
Test4 [aa] [15:36:00]

The number of repetitions is the number of data records stored in my database. how can I display the data from the first entry?
For example:
Test1 [aa] [15:36:00]

Test2 [aa] [15:36:00]

Test3 [aa] [15:36:00]
Test4 [aa] [15:36:00]

Thank you again ~ ^

------ Solution --------------------
Correct row.
While ($ row = mysql_fetch_array ($ result )){

Discussion

// $ Row = mysql_fetch_array ($ result); // deleted
While ($ rows = mysql_fetch_array ($ result )){

------ Solution --------------------
Your $ row has never changed. it must be the same data.
------ Solution --------------------
$ Query = "SELECT * from news ORDER by id desc Limit $ offset, $ page_size ";
$ Result = mysql_query ($ query, $ conn );

// $ Row = mysql_fetch_array ($ result); this row is placed in the while condition.
No need for this $ I
// While ($ I <$ rows = mysql_num_rows ($ result )){
// $ I ++;


While ($ row = mysql_fetch_array ($ result )){
Echo"

";
Echo"








";Echo" ";Echo" ";Echo" ";Echo" ";Echo" ";}Echo"
";
Echo "". $ row ["title"]. "";
Echo"
";
Echo "[". $ row ["author"]. "]";
Echo"
";
Echo "[". $ row ["date"]. "]";
Echo"
";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.