![](/img/trans.png)
[英]How to retrieve the values from the mysql table which are not having default value
[英]How to retrieve the table values form MySql
我在mysql中有一个这样的表:
Id Name course_type module
-----------------------------------
1 php E scorm
2 java E test
3 php C test
4 php C scorm
我想检索列course_type
其中有Name = 'Php'
和module ='Scorm'
。
为此,我使用以下查询:
$sql= "select * from course where course_id='".$cou."' and module_name ='scorm' ";
$rete = mysql_query($sql);
foreach($rete as $reti) {
$co_ty =$reti->course_type;
}
如果我打印$co_ty
表示显示EC。
我想要的是,如果course_type
为E表示输出将为E-learn,如果course_type
为C表示输出将为Class。
但是,如果对于相同的名称“ Php”, course_type
既是“ E”又是“ C”,并且模块“ Scorm”意味着输出将是“ Both”
怎么做? 为此,我正在尝试以下代码:
if($co_ty == 'E') {
echo 'E-Learning';
} else if ($co_ty=='C') {
echo 'Classroom';
}
else {
echo 'Both';
}
但是结果只会是电子学习。
我不知道如何获得这个价值。 请任何人帮我
您的代码的问题是您正在检查else if条件。 结果是一个数组,因此它首先找到E并仅打印E-Learning,然后离开执行else条件。
您应该尝试此代码...希望对您有所帮助...
if($co_ty == 'E'){
echo 'E-Learning';
} if($co_ty=='C'){
echo 'Classroom';
}
Try changing your code as below:
$sql= "select * from course where course_id='".$cou."' and module_name ='scorm' ";
$rete = mysql_query($sql);
$co_ty = '';
foreach($rete as $reti)
{
$co_ty .=$reti->course_type;
}
if($co_ty == 'E')
{
echo 'E-Learning';
}
else if($co_ty=='C')
{
echo 'Classroom';
}
else`enter code here`
{
echo 'Both';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.