mssql_fetch_assoc中的数组[关闭]

I have a query that returns several arrays, where each array have 2 positions (0 and 1). How can i merge this result to a single array, where i dont want the first position (0), only the second position?

//execute the SQL query and return records
$result = mssql_query($query);
$numRows = mssql_num_rows($result); 

//display the results 
for ($i=0;$i<numRows ;$i++) {

$row = mssql_fetch_assoc($result);
echo "<pre>";print_r($row); echo "</pre>";
}
$result = mssql_query($query);
$data = array();
while ($row = mssql_fetch_assoc($result))
{
    $data[] = $row;
}
var_dump($data);

Getting only the second value would change the $data = line to $data[] = $row[1];

You may want to use mssql_fetch_object instead, or if you are using mssql_fetch_assoc, you're probably better off using the associative index instead of the numerical one. Your code is a lot more readable if you use $row->FieldName or $row["FieldName"] rather than $row[1].

When you resolve your issue, I would suggest switching to mysqli_fetch_assoc(), as mysql functions are now deprecated.

http://php.net/manual/en/function.mysql-fetch-assoc.php

http://www.php.net/manual/en/mysqli-result.fetch-assoc.php

If you don't want the first value then you don't need to merge. I would create a second array like this:

while($rows = mssql_fetch_array($result))
{
   newArr[] = $rows[1] ;
}

That should populate the newArr array with only the second value of your current array.