Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从一个表而不是一个id中获取多个详细信息?_Php_Mysql - Fatal编程技术网

Php 如何从一个表而不是一个id中获取多个详细信息?

Php 如何从一个表而不是一个id中获取多个详细信息?,php,mysql,Php,Mysql,我如何从一个表中获取多个详细信息而不是一个id,我可以使用if…..从表中获取更多数据。。。。。更多解释和代码如下 id | class | gender | score | date ----------------------------------------------------------------------------------- 1 | pry1 | male | ,first, first, fi

我如何从一个表中获取多个详细信息而不是一个id,我可以使用if…..从表中获取更多数据。。。。。更多解释和代码如下

    id  | class  | gender |         score           | date
    -----------------------------------------------------------------------------------
    1   | pry1   |  male  | ,first, first, first    | ,2019-12-04,2019-11-21,2019-11-20
    2   | pry2   | female | ,second, second, second | ,2019-12-04,2019-11-21,2019-11-20
    3   | pry3   |  male  | ,first, first, first    | ,2019-12-06,2019-12-13,2019-12-19 
    4   | pry4   |  male  | ,third, third, third    | ,2019-12-20,2019-12-20,2019-12-20     
    5   | pry5   | female | ,second, second         | ,2019-12-24,2019-12-24,2019-12-24

     ////////i selected e1view from the database /////////////

            if (substr_count($e1view, ",") <'3') 
                  {
                    
                    $last=0;
                  }

            elseif (substr_count($e1view, ",") =='3' OR $m1==='0') {
                
                  $last = ltrim(strrchr($e1view,','),',');

                  if ($last =='first') {
                        $last=1;
                    }
                    else if($last=="second"){
                        $last=2;
                    }
                    else if($last=="third"){
                        $last=3;
                   
                    }
使用
explode()
将字符串拆分。使用关联数组将单词转换为可以添加的数字

$place_map = ['first' => 1, 'second' => 2, 'third' => 3];
$query = "SELECT scores FROM yourTable WHERE gender = 'male'";
// perform the query ...
$finalScoreforallmaleStudent = 0;
while ($row = $result->fetch_assoc()) {
    $scores = explode(',', $row['scores']);
    $last_score = trim($scores[count($scores)-1]);
    $finalScoreforallmaleStudent += $place_map[$last_score];
}
echo $finalScoreforallmaleStudent;
使用
explode()
将字符串拆分。使用关联数组将单词转换为可以添加的数字

$place_map = ['first' => 1, 'second' => 2, 'third' => 3];
$query = "SELECT scores FROM yourTable WHERE gender = 'male'";
// perform the query ...
$finalScoreforallmaleStudent = 0;
while ($row = $result->fetch_assoc()) {
    $scores = explode(',', $row['scores']);
    $last_score = trim($scores[count($scores)-1]);
    $finalScoreforallmaleStudent += $place_map[$last_score];
}
echo $finalScoreforallmaleStudent;


简言之,您不能使用
isset
获取除真/假以外的任何信息,因此希望它有助于返回
多个详细信息
-查看其他方法吗?
isset()
与此无关。如果你只想要男生,你可以在查询中使用
WHERE
WHERE gender='male'
hello,@Barmar,我正试图在一个日期范围内搜索,我有日期栏,因为我在帖子中编辑过,先生,我无法获取。感谢期待您的帮助您好,先生@Barmar,我已经在这里创建了它。简而言之,您不能使用
isset
获取除真/假以外的任何信息,因此希望它能够帮助返回
多个详细信息
-看到其他方法了吗?
isset()
与此无关。如果你只想要男生,你可以在查询中使用
WHERE
WHERE gender='male'
hello,@Barmar,我正试图在一个日期范围内搜索,我有日期栏,因为我在帖子中编辑过,先生,我无法获取。感谢期待您的帮助您好,先生@Barmar,我已经在这里创建了它,我会尝试这个,但实际上,来自该字段的详细信息是在一个数组中获得的,我应该直接发布在这里还是在上面的代码中?如果您没有完整描述详细信息,请更新问题。我已经更新了它,谢谢你为什么会在数据库中使用这样一种可调的格式?把数字像你原来的表格一样放进去。将其转换为PHP中的文字。我将尝试此方法,但实际上,来自该字段的详细信息是以数组形式获取的,我是否应将其直接发布在此处或上面的代码中?如果您没有完整描述详细信息,请更新该问题。我已更新了它,谢谢。为什么您会在数据库中使用这样的horible格式?请将数字与原始表格一样。将其转换为PHP中的单词。