Why can't I traverse the output table with while

Source: Internet
Author: User
A very common query output function now has 10 data calls in the table because you want to convert the result to XML so you can't do echo in the body of the function, but so the call can only output the last record, the method can call Echo main_shopactive () in the calling page to output the whole table content; function body Functions main_shopactive () {//Arcade activity query, return the last activity record of the reverse sort $conn = Mysql_connect_conn (); $sql = "SELECT * FROM Wx_active ORDER BY id desc-Limit 0,30 "; $rs = mysql_db ($sql, $conn) or Die (' Query logging failed! '); if (mysql_num_rows ($rs) > 0) {while ($row = Mysql_fetch_assoc ($rs)) {$my _active = $row [' concent '];}} else{$my _active = ' NO active ';} return $my _active;}


Reply to discussion (solution)

while ($row = Mysql_fetch_assoc ($rs))
{
$my _active[] = $row [' concent '];
}

Upstairs positive solution,.

The return value is an array, called?

How do I read all the in-table values at once?

foreach (Main_shopactive () as $v) echo $v. '
';

You can
$my _active. = $row [' concent '];
return $my _active;

can also
$my _active[] = $row [' concent '];
Return join (', $my _active);

Moderator How is your first method different from my original code?

The difference is that one more point
Don't underestimate this, and with it there is a qualitative change.

Moderator boss very strange phenomenon ah. Dior Shiseido It's two. The following should have floor location classification, now all connected together
The result should be this: '? Dior first Floor cosmetics 0412-8999960 Shiseido First floor cosmetics 0412-89999961 '
Now it is: ' Dior Shiseido first floor 0412-89999600412-89999961 Cosmetic cosmetics '
What's the reason? The order of the fields is completely wrong.

Invoke page

$floor _find = new Floor_product_lookfor (), Echo ($floor _find->floor_product (' first floor ');


The original class and function class Floor_product_lookfor{function floor_product ($floor _nunmer) {$conn = Mysql_connect_conn (); $sql = "SELECT * From Wx_floor where Goods_floor = ' $floor _nunmer ' ORDER by goods_id desc '; $rs = mysql_db ($sql, $conn) or Die (' query record failed! '); if (mysql_num_rows ($rs) > 0) {while ($row = Mysql_fetch_assoc ($rs)) {$floor. = $row [' Goods_name ']; $name. = $row [' Goods_ Floor ']; $tel. = $row [' Goods_tel ']; $type. = $row [' Goods_type '];}} else{$floor = ' NO GOODS information ';} Return ($floor. $name. $tel. $type);}}

Is it because there are more than 2 fields that cannot be used. Connection

There's nothing to be surprised about.
Now that you've simplified your code (no delimiters between records), of course it's mixed up.
At least you need to give the data format you expect.

In fact, the generation of XML node data can be done directly in the SQL instructions

In fact, it is not a simplification, but I think this method can be used to put into other functions of the general. Because it is only with his fixed interface and code ~
This effect is what I expected, trouble moderator adult
?

Dior First Floor cosmetics 0412-8999960 Shiseido First Floor cosmetics 0412-89999961

while ($row = Mysql_fetch_assoc ($rs))
{
$value. = $row [' Goods_name ']. $row [' Goods_floor ']. $row [' Goods_tel ']. $type. = $row [' Goods_type '];
}
return $value;

Thank you!

  • 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.