Filling an array with values from a single column over specific rows in MySQL DB
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:
This is how I'm calling to get the results of that function:
At the moment, I'm doing a print_r of the array to show the contents, like so:
Array (  => 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...
mysql_fetch_array only returns the first row of the result and then moves the internal data pointer ahead. The array has 2 entries because 1 is for the numeric indexed array and the other one is for the associative array. what you can do is replace this:
From the manual:
mysql_fetch_row() - Get a result row as an enumerated array
mysql_fetch_array() - Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc() - Fetch a result row as an associative array
mysql_fetch_object() - Fetch a result row as an object
Wow! So straightforward. Thanks so much! Works like a dream.
|All times are GMT. The time now is 03:01 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0