Cyclic result sets are different in nature.

Source: Internet
Author: User
$sql = "SELECT * from a where id= ' $Id '"; $result = $mysqli->query ($sql), while ($r = $result->fetch_assoc ()) {echo $r. '
';//Cycle 5 times. }


The result is

1: Name 2
2: Name 1
3: Name 1
4: Name 3
5: Name 1

If only 1 times the name 1 in the loop, how is it written?


Reply to discussion (solution)

Don't know how your data is organized!
An ID actually corresponds to 5 records

Besides $r = $result->fetch_assoc () is the array
You echo $r. '
'; It's impossible to get what you're saying.

$sql = "SELECT * from a where id= ' $Id '"; $result = $mysqli->query ($sql), while ($r = $result->fetch_assoc ()) $r =array_ Unique ($r);p Rint_r ($r)

Don't know how your data is organized!
An ID actually corresponds to 5 records

Besides $r = $result->fetch_assoc () is the array
You echo $r. '
'; It's impossible to get what you're saying.

The structure of the data is that
A table name B table Article

According to the article B of the latest and newest, call a table name, said who updated the article.
If 1 people have updated the N article continuously, it repeats.

$sql = "SELECT * from a where id= ' $Id '"; $result = $mysqli->query ($sql), while ($r = $result->fetch_assoc ()) $r =array_ Unique ($r);p Rint_r ($r)


This is also a way, but I am this is 2 tables at the same time query. This is a good idea if you use a view.

Query Plus DISTINCT Property

Suggest that you put out your
Create Table ....;
Insert into Table .... Statement

What are the expected results, and simply describe the algorithm logic.

Suggest that you put out your
Create Table ....;
Insert into Table .... Statement

What are the expected results, and simply describe the algorithm logic.

Complete the following. Trouble to see.

$c = "Select A.id,a.name,a.dcname,a.curl,a.item1,b.nid, b.xclass,b.title,b.nurl,b.createdate from XClass a,news b where    A.name=b.xclass ORDER by Nid desc limit 0,15 "; $result = $mysqli->query ($c), while ($rsrow = $result->fetch_assoc ()) {    $xsURL = "; if ($rsrow [' CURL ']== ') {$xsURL = $rsrow [' id '];}    else{$xsURL = $rsrow [' CURL '];}    $zjURL = "; if ($rsrow [' Nurl ']== ') {$zjURL = $rsrow [' Nid '];}    else{$zjURL = $rsrow [' Nurl '];}    $chadaleiName = $rsrow [' dcname '];    $chadalei = "SELECT * from Dclass where name= ' $chadaleiName '";    $cha = $mysqli->query ($chadalei);    $chaRs = $cha->fetch_assoc ();    $LEIBIEURL = "; if ($chaRs [' CName ']== ') {$leibieUrl = $chaRs [' Id '];}    else{$leibieUrl = $chaRs [' CName '];}    $cha->free ();    $shijian = $rsrow [' CreateDate ']; $zj. = '
  • ['. $chaRs [' Name ']. ']'; $zj. = '. $rsrow [' Xclass ']. '; $zj. = '. $rsrow [' Title ']; $zj. = '. $rsrow [' Item1 ']. ' '. Date (' H:i:s ', Strtotime ($shijian)). '
  • '; $zj. = $xsURL. '--'. $rsrow [' Xclass ']. ' -'. $zjURL. '-' $rsrow [' Title ']. ' --
    ';}
  • Related Article

    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.