Forum Moderators: coopster

Message Too Old, No Replies

Assigning PHP array key and values

         

ryan_b83

3:30 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



Hello, I am having difficulty with this script. I am trying to assign specific values to the $pid_list array. For example

$pid_list[121] = 1
$pid_list[122] = 1

and so forth. But when I try to assign these values it just auto-increments the $pid_list[$k] key value to 0,1,2... and so forth... Here is a snippet of code, i just included the whole while loop, but i think the error is just one of the end lines where i assign the values to the array.

while($purchase1_row = mysql_fetch_assoc($purchase_result)){
$sql = "SELECT `order_progress` FROM `order` WHERE `pid` = '".$purchase1_row['pid']."'";
$order_result = mysql_query($sql) or die("SQL ERROR: ".__LINE__.mysql_error());

$lowest_progress = 99;
while($order_row = mysql_fetch_assoc($order_result)){
if($order_row['order_progress'] < $lowest_progress){
$lowest_progress = $order_row['order_progress'];
}
}
echo "PROW = ".$purchase1_row['pid']."<br>"; // *** THIS IS WHERE I ASSIGN THE VALUES TO TEST THAT I HAVE THE CORRECT PID
$pid_list[$purchase1_row['pid']] = $lowest_progress; //*** THIS IS WHERE I ASSIGN THE VALUES TO THE ARRAY BUT IT JUST GIVES ME A 0, 1, 2... VALUE INSTEAD OF THE PID VALUE
}

sort($pid_list);

foreach($pid_list as $k => $v){
echo $k." = ".$v."<br>";
}

*********OUTPUT***********

PROW = 127
PROW = 125
PROW = 123
PROW = 130
PROW = 131
PROW = 132
PROW = 133
PROW = 134
PROW = 135
PROW = 136
PROW = 137
PROW = 138
PROW = 139
PROW = 141
0 = 1
1 = 1
2 = 2
3 = 3
4 = 3
5 = 3
6 = 3
7 = 3
8 = 3
9 = 3
10 = 3
11 = 4
12 = 4
13 = 5

Hope i didn't make this more confusing than it needs to be, but i think it is just a dumb mistake on my behalf? any suggestions?

Thanks,
Ryan

ryan_b83

4:08 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



Sorry everyone.... i figured it out...

asort($pid_list);

instead of just the regular sort...