Reputation: 4003
Not as simple as it sounds I believe, but I have the following and trying to print the month name from date provided.
public function convertEngDateToAr($engDate)
{
//SELECT MONTHNAME('2009-05-18');
$connectionInstance = new ConnectionClass();
$connection = $connectionInstance->connectToDatabase();
$monthResult = $connection->query("SELECT MONTHNAME('$engDate')");
//echo "Month: " . $monthResult;
while($row = $monthResult->fetch_assoc())
{
print_r($row);
}
}
The above gets me this output:
Array ( [MONTHNAME('2012-08-21')] => August )
How can I get August alone out of the array and store it in variable? The only weird thing here is that the index in the array is just strange.
Thank
Upvotes: 0
Views: 60
Reputation: 11354
You can either use SELECT MONTHNAME(xxxx) AS monthName
or you could return an indexed array instead of an associative one:
while($row = $monthResult->fetch_row())
echo $row[0] . "\n";
Upvotes: 1
Reputation: 33522
Try changing SELECT MONTHNAME('$engDate')"
to SELECT MONTHNAME('$engDate') as monthName"
Then you should see:
Array ( monthName => August )
Then you can use:
while($row = $monthResult->fetch_assoc())
{
$myMonth=$row['monthName'];
}
Upvotes: 3