I have a table in mysql like this:
Id Name course_type module
-----------------------------------
1 php E scorm
2 java E test
3 php C test
4 php C scorm
I want to retrieve the column course_type
which has Name = 'Php'
and module ='Scorm'
.
For this I am using the following query:
$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;
}
If I print the $co_ty
means it display the EC.
What I want is if the course_type
is E means the output will be E-learn, and if the course_type
is C means the output will be Class.
But if the course_type
is both 'E' and 'C' for the same Name 'Php' and module 'Scorm' means the Output will be 'Both'
How to do that? For this I am trying this code:
if($co_ty == 'E') {
echo 'E-Learning';
} else if ($co_ty=='C') {
echo 'Classroom';
}
else {
echo 'Both';
}
But the result will be E-learn only.
I don't know how to get this value. Please anyone help me
the problem for ur code is that You are checking in else if condition. The result is an array, so it find E at first and print only E-Learning and then it leave the execution of the else condition.
You should try this code... hope it helps...
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';
}
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.