View Single Post
Old 11-11-2010, 09:20 AM   #1 (permalink)
gj384
The Visitor
 
Join Date: Nov 2010
Posts: 2
Thanks: 1
gj384 is on a distinguished road
Default Filling an array with values from a single column over specific rows in MySQL DB

Hi there,

I'm trying to populate a single-column array with values from one column in MySQL, but only from certain rows in which a specific other column matches a certain string. This is my function:

PHP Code:
function getProductList($field,$term){
      
$q "SELECT PartNo FROM ".TBL_PRODUCTS." WHERE ".$field." = '".$term."'";
      
$result mysql_query($q$this->connection);
      
$dbarray mysql_fetch_array($result);
      return 
$dbarray;
   } 
"$field" is the name of the column I'm searching, and "$term" is the actual string I'm searching for in that column. "PartNo" is the name of the column from which I want to draw the results, which I then want placed into the array.

This is how I'm calling to get the results of that function:

PHP Code:
$compatibleProductsArray=$database->getProductList("Cat",$productInfo[2]); 
In the code above, the name of the column I'm searching is "Cat", and the string I'm searching for is stored in "$productInfo[2]".

At the moment, I'm doing a print_r of the array to show the contents, like so:

PHP Code:
print_r($compatibleProductsArray); 
Which gives me the following output:

Array ( [0] => T7S25T [PartNo] => T7S25T )

But I'm expecting many more rows than that... What am I doing wrong?

Incidentally, after I work out how to fill the array, I'm then planning to convert the array into a CSV string. Is there an easy way to do that, or does knowing that final goal make it any easier to work out a solution to all of the above?

Thanks a million, in advance...
gj384 is offline  
Reply With Quote