显示多个应该显示的单值 - php

时间:2014-03-25 18:36:01

标签: php mysql sql

所以我正在编写一个php脚本,由于某种原因不允许我将相关信息打印到csv的同一列。我首先要查询数据库以构建基本用户配置文件,然后根据唯一ID填充该用户的信息。我当时想要做的是检索与该用户相关联的分数,并将它们发布到一个列中,该特定用户定义信息将显示的行。然而,尽管他们有很多与他们相关的分数,但我的努力让我为每个用户制作了一个单独的分数。我已将代码放在下面:

while ($row = mysql_fetch_array($answers, MYSQL_BOTH)) {
    if ($last_uniq_id != $row[0]) {
        $i++;
        $k=2;

        $last_uniq_id = $row[0];
    }

    $myarray[$i][0] = $row[0];
    $myarray[$i][1] = $row[1];
    $myarray[$i][$k] = str_replace('"', '""', $row[3]);

    $k++;

    if ($k == $length) {
        $first_speaker=1;
        // Get all speakers
        $query = "SELECT * FROM v_events_abstracts_speakers WHERE abstract_id='".$row[0] ."' ORDER BY speaker_id ASC";

        $result_speakers = mysql_query($query) or die('Query failed: ' . mysql_error());
        $num_speakers = mysql_num_rows($result_speakers);


        while ($row_sp = mysql_fetch_array($result_speakers, MYSQL_BOTH)) {
            if ($first_speaker==1) {
                $myarray[$i][$length] = str_replace("\"", "\"\"", $row_sp[first_name]);
                $myarray[$i][$length + 1] = str_replace("\"", "\"\"", $row_sp[last_name]);
                $myarray[$i][$length + 2] = str_replace("\"", "\"\"", $row_sp[title]);
                $myarray[$i][$length + 3] = str_replace("\"", "\"\"", $row_sp[organization]);
                $myarray[$i][$length + 4] = str_replace("\"", "\"\"", $row_sp[phone]);
                $myarray[$i][$length + 5] = str_replace("\"", "\"\"", $row_sp[email]);
                $myarray[$i][$length + 6] = str_replace("\"", "\"\"", $row_sp[xperience_level]);
                $myarray[$i][$length + 7] = str_replace("\"", "\"\"", $row_sp[bio]);
                $myarray[$i][$length + 8] = str_replace("\"", "\"\"", $row_sp[url]);
                $myarray[$i][$length + 9] = str_replace("\"", "\"\"", $row_sp[status]);
                $myarray[$i][$length + 10] = $row[4];
                $myarray[$i][$length + 11] = str_replace("\"", "\"\"", $row_sp[twitter]);               
                $first_speaker=2;
            } else {
                $i++;
                for ($m = 0; $m < $length; $m ++) {
                    $myarray[$i][$m] = "";
                }               
                $myarray[$i][0] = $row[0];
                $myarray[$i][1] = $row[1];
                $myarray[$i][$length] = str_replace("\"", "\"\"", $row_sp[first_name]);
                $myarray[$i][$length + 1] = str_replace("\"", "\"\"", $row_sp[last_name]);
                $myarray[$i][$length + 2] = str_replace("\"", "\"\"", $row_sp[title]);
                $myarray[$i][$length + 3] = str_replace("\"", "\"\"", $row_sp[organization]);
                $myarray[$i][$length + 4] = str_replace("\"", "\"\"", $row_sp[phone]);
                $myarray[$i][$length + 5] = str_replace("\"", "\"\"", $row_sp[email]);
                $myarray[$i][$length + 6] = str_replace("\"", "\"\"", $row_sp[experience_level]);
                $myarray[$i][$length + 7] = str_replace("\"", "\"\"", $row_sp[bio]);
                $myarray[$i][$length + 8] = str_replace("\"", "\"\"", $row_sp[url]);
                $myarray[$i][$length + 9] = str_replace("\"", "\"\"", $row_sp[status]);
                $myarray[$i][$length + 10] = $row[4];
                $myarray[$i][$length + 11] = str_replace("\"", "\"\"", $row_sp[twitter]);                   
            }
        }

    **// Get Evaluation Form Questions
    $query = 'SELECT * FROM v_events_abstracts_votes WHERE abstract_id='.$row['uniq_id'];
    $arrQuestions = mysql_query($query) or die('Query failed: ' . mysql_error());

    $last_vote_id="";
    $last_abstract_id = $row['uniq_id'];

    while($rows = mysql_fetch_array($arrQuestions)){
        if($last_abstract_id == $rows['abstract_id']):
        $myarray[$i][$length + 12] = $rows['vote_result'];
    else:
        $last_abstract_id == $rows['abstract_id'];
    endif;

    }**


    }



}

代码的第一部分通过填写预设列来构建用户配置文件。我遇到问题的部分用**表示。我的想法是将last_value设置为$ row的初始值[&#39; uniq_id&#39;]。从那里进入while循环。如果last_value等于用户的id(在本例中我称为抽象id - 我知道可怕的名字),则打印出该列。如果没有,则将其设置为当前用户并再次执行该过程。但是就像我说的那样,每个用户只能得到一个分数。

任何帮助将不胜感激

0 个答案:

没有答案