$sql =mysql_query ("Select B.userid,b.username,b.card_no,b.buytime,b.commission1,m.level from Buybak B left Joinmember M on B.userid=m.userid where m.agentid= ' ". $user [UserID]." ' and b.status1>=0 ");
$array = @mysql_fetch_array ($level 1_orders);
foreach ($array as $rows) {
echo $rows. '
';//loop output two arrays of information
echo $rows [' userid ']. '
';//This only outputs the first character of each element, if the value of username is test, then the T is output. What's going on?
}
With the while to output normally, I want to know how to use the foreach output
Reply to discussion (solution)
$array = @mysql_fetch_array ($level 1_orders);
Print_r ($array); Look what it is.
$array = @mysql_fetch_array ($level 1_orders);
Print_r ($array); Look what it is.
Print_r ($array) only outputs an array, while the two-dimensional array is looped, and two is the right one. foreach has no way of printing subscript.
Array
(
[0] = 3
[UserID] = 3
[1] = Test3
[Username] = Test3
[2] = VIP
[Card_no] = VIP
[3] = 2016-02-16 14:53:33
[Buytime] = 2016-02-16 14:53:33
[4] + = {"1": 5, "2": 8, "3": 10, "4": 12}
[Commission1] = {"1": 5, "2": 8, "3": 10, "4": 12}
[5] = 1
[Level] = 1
)
What is the while loop, print out the output to see
Second, the foreach traversal above you is traversing a two-dimensional array, but your $array is obviously a one-dimensional array.
$array = @mysql_fetch_array ($level 1_orders);
Print_r ($array); Look what it is.
This is the while loop, and this is right.
Array
(
[0] = = Array
(
[0] = 2
[id] = 2
[1] = 3
[UserID] = 3
[2] = Test3
[Username] = Test3
[3] = VIP
[Card_no] = VIP
[4] = 2016-02-16 14:53:33
[Buytime] = 2016-02-16 14:53:33
[5] + = {"1": 5, "2": 8, "3": 10, "4": 12}
[Commission1] = {"1": 5, "2": 8, "3": 10, "4": 12}
[6] = 1
[Level] = 1
)
[1] = = Array
(
[0] = 10
[id] = 10
[1] = 8
[UserID] = 8
[2] = Test8
[Username] = Test8
[3] = VIP
[Card_no] = VIP
[4] = 2016-02-16 14:59:13
[Buytime] = 2016-02-16 14:59:13
[5] + = {"1": 5, "2": 8, "3": 10, "4": 12}
[Commission1] = {"1": 5, "2": 8, "3": 10, "4": 12}
[6] = 1
[Level] = 1
)
)
Mysql_fetch_array ($level 1_orders) returns a one-dimensional array
So you need to use the while loop to execute mysql_fetch_array to read all the results
Traversing a one-dimensional array requires only one loop, and you're not going to have to use two of them naturally.