I have been really stuck on figuring out how to build an array for json_encode.
I am looping through an array of column names, querying the database for distinct values and then trying to load those distinct values into an array to pass to json_encode. I can’t see to get the correct format, so the json is not being formatted correctly.
I need this format,
[["1001","1002","1003"],["Lura Baggs","Dominga Conary","Randolph Kiester"]]
But I can’t seem to get it. Here is my code,
[php]
$sTable = “People”;
$aColumns = array( ‘FName’, ‘LName’ );
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
//echo($i);
$sQuery = "
SELECT DISTINCT “.$aColumns[$i].”
FROM $sTable
";
$rSelectList = mysql_query( $sQuery, $gaSql[‘link’] ) or die(mysql_error());
$j = 0;
$vSelectValue = $vSelectValue."[";
while($row = mysql_fetch_array($rSelectList)){
$aSelectList[i][j] = $row;
$j++;
}
[/php]
Which should, in my limited knowledge of PHP, add the value of the $row to an array, then I can json_encode the array so that it will be formatted like the example above.
What am I missing here?
Thanks in advance,
Drew