I'm selecting a single column from my mysql database:
$savedSQL = 'SELECT can_id FROM savedsearches WHERE user_id = "'.mysql_real_escape_string($user_id).'" AND insertTime >= "'.$lastSigTime.'"';
$savedQuery = mysql_query($savedSQL);
And I'd like to return the values as a single dimension, enumerated array such that array[0] = row1, array[1] = row2, etc.
When I put it into an array like this:
while($savedResult = mysql_fetch_array($savedQuery))
{ $savedArray[] = $savedResult; }
It returns it as a multi-dimension array so that array[0][0] = row1, array[1][0] = row2, etc.
I was thinking of adding something like this:
while($i=0;$i<count($savedArray);$i++)
{
$newSavedArray[$i] = $savedArray[$i][0]
}
But is there an easier, more efficient way to accomplish this?
You're very close. You just need to access $savedResult[0]
to retrieve your column, and append it onto $savedArray
while($savedResult = mysql_fetch_array($savedQuery)) {
$savedArray[] = $savedResult[0];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With