如何从带变量的日期获取日期名称

时间:2017-04-06 09:34:39

标签: php html function mysqli

我想使用功能DAYNAME,但是会从表单中获取此日期,并且取决于星期几,创建表单的人将获得更多积分

我觉得这样的事情

if ($row['DAYNAME($Data)'] == "Monday") {
$suma1=1;
} elseif ($row['DAYNAME($Data)'] == "Tuesday"){
    $suma1=1;
} elseif ($row['DAYNAME($Data)'] == "Wednesday"){
    $suma1=1;
} elseif ($row['DAYNAME($Data)'] == "Thursday"){
    $suma1=1;
} elseif ($row['DAYNAME($Data)'] == "Friday"){
    $suma1=1;
} elseif ($row['DAYNAME($Data)'] == "Saturday"){
    $suma1=2;
} elseif ($row['DAYNAME($Data)'] == "Sunday"){
    $suma1=2;
}

问题出在这里

我有这个...

 <?php
$db = "sp28";  
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);  
foreach($dbh->query('SELECT DAYNAME("2017-04-06")') as $row) {  
echo "<tr>";  
echo "<td>" . $row['DAYNAME("2017-04-06")'] . "</td>";   
echo "</tr>";  

但我想要这样,DAYNAME中的变量,但它不起作用

<?php
$Data="2017-04-06";
$db = "sp28";  
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);  
foreach($dbh->query('SELECT DAYNAME("$Data")') as $row) {  
echo "<tr>";  
echo "<td>" . $row['DAYNAME("$Data")'] . "</td>";   
echo "</tr>";  

}
?>  

0 个答案:

没有答案