Why can't I traverse the output table with WHILE?
A very common query output function currently has 10 data records in the table. because the results need to be converted into XML, echo cannot be performed in the function body. However, in this case, only the last record can be output, find the method to output the whole table content on the call page and call echo main_shopactive (); function body function main_shopactive () {// mall activity query, returns the last event record of reverse sorting $ conn = mysql_connect_conn (); $ SQL = "SELECT * FROM wx_active order by id desc limit"; $ rs = mysql_db ($ SQL, $ conn) or die ('query record failed! '); If (mysql_num_rows ($ rs)> 0) {while ($ row = mysql_fetch_assoc ($ rs) {$ my_active = $ row ['concent'];} else {$ my_active = 'No Activity';} return $ my_active ;}
Reply to discussion (solution)
While ($ row = mysql_fetch_assoc ($ rs ))
{
$ My_active [] = $ row ['concent '];
}
Upstairs ,..
The returned value is an array. what about the call?
How can I read the values in all tables at one time?
Foreach (main_shopactive () as $ v) echo $ v .'
';
You can
$ My_active. = $ row ['concent '];
Return $ my_active;
Yes.
$ My_active [] = $ row ['concent '];
Return join ('', $ my_active );
Moderator, what is the difference between your first method and my original code?
The difference is that there is one more point.
Don't underestimate this point. with it, there will be a qualitative change.
The moderator is very strange. Dior Shiseido: These two products should be classified by floor and location respectively. now they are all connected together.
The result should be like this :'? Dior 1st floor cosmetics 0412-8999960 Shiseido 1st floor cosmetics 0412-89999961'
But now it is like this: 'Dior Shiseido first floor 0412-89999600412-89999961 cosmetic cosmetics'
Why? The order of fields is totally incorrect.
Call page
$ Floor_find = new floor_product_lookfor (); echo ($ floor_find-> floor_product ('1st floor '));
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 two fields that cannot be connected.
Nothing strange
Since you simplified your code (without providing the delimiter between Records), it is of course mixed together.
At least you need to provide the expected data format
In fact, xml node data can be directly generated in SQL commands.
In fact, it is not simplified, but I thought this method can be used in other functions. Because it can only use its fixed interfaces and code ~
This effect is what I expected, and it is troublesome for the moderator.
?
Dior cosmetics on the first floor 0412-8999960 Shiseido cosmetics on the first floor 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!