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
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'];
}
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";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.