954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to combine 2 fields become one array

Table's name: grandTotal
(have two fields :defect_code and total)

defect_code total
LM 23
FM 15
DF 5

How this data can be an array like this
array("LM" >=23, "FM">=15,"DF">=5) using query? please help me..:S

shamsidah
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

...

while($row = mysql_fetch_array($result)){
  $myarray[$row['defect_code']] = $row['total']; 
}
//check with:
print_r($myarray);
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This should work:

<?php
# ...
# connection code
# ...

$q = mysql_query('select defect_code, total from grandTotal');
$a = array();
while($row = mysql_fetch_object($q))
{
    $a[$row->defect_code] = $row->total;
}

print_r($a); # display array
?>

bye :)

ooops ardav, I just saw your reply, sorry.. :D

cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

Aha, cereal you OOPed it. Nice. :)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Table's name: grandTotal (have two fields :defect_code and total)

defect_code total LM 23 FM 15 DF 5

How this data can be an array like this array("LM" >=23, "FM">=15,"DF">=5) using query? please help me..:S


Thanks!! really appreciate

shamsidah
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You