将字符串分成数组

时间:2014-04-26 17:26:27

标签: php mysql arrays

我在mysql表中有一个字段,它将ProjectTeam值存储为(val1,val2) 我想将ProjectTeam中的每个值都放到HTML中,每个值必须链接到一个单独的链接。 我怎样才能回显每个数组元素。下面的代码显示正确,但所有值都标识为一个链接。任何帮助表示赞赏。

function list_account_projects($new_projectAccount){
    $this->projectAccountName = $new_projectAccount;
    $listQuery = mysql_query("SELECT * from projects 
           WHERE projectAccount = '$this->projectAccountName'");

    while  ($rows = mysql_fetch_array($listQuery)){
        $this->projectName = $rows['projectName'];
        $this->projectType = $rows['projectType'];
        $this->projectTeam = $rows['projectTeam'];
        $this->projectOwner= $rows['projectOwner'];
        $this->projectStartDate = $rows['projectStartDate'];

        //Convert date backwards 
        $re_projectStartDate = date('m-d-y', strtotime($this->projectStartDate));

     //split ProjectTeam ',' - Optional
     $splitUsers = explode( ',', $this->projectTeam );
       foreach( $splitUsers as $user ) {
                  $user = trim( $user );
            }


        echo "
             <div class=\"list-group\">
             <a class=\"list-group-item active\" href=\"#\">$this->projectName <p class=\"pull-right\">Due Date: $re_projectStartDate</p></a>
              <a class=\"list-group-item \" > 
                     Project Name: $this->projectName</br>
                     Project Type:  $this->projectType</br>
                     Project Owner: $this->projectOwner</br>
                   Project Team: <a href=\"$user\">$user</a></a>
                         </div>
                     ";

    }

2 个答案:

答案 0 :(得分:0)

你可以像这样取值 echo应该像这样回应你的变量

echo "<div class=\"list-group\">".$example."</div>";

while  ($rows = mysql_fetch_array($listQuery)){
        $projectName = $rows['projectName'];
        $projectType = $rows['projectType'];
        $projectTeam = $rows['projectTeam'];
        $projectOwner= $rows['projectOwner'];
        $projectStartDate = $rows['projectStartDate'];

然后你可以像那样打印它们

 echo "
             <div class=\"list-group\">
             <a class=\"list-group-item active\" href=\"#\">".$projectName ."<p class=\"pull-right\">Due Date:". $re_projectStartDate."</p></a>
              <a class=\"list-group-item \" > 
                     Project Name:". $projectName."</br>
                     Project Type:".  $projectType."</br>
                     Project Owner:". $projectOwner."</br>
                   Project Team: <a href='".$projectTeam."'>".$projectTeam."</a></a>
                         </div>
                     ";

答案 1 :(得分:0)

您无法使用嵌套的代码,请尝试使用此代码,

echo " <div class=\"list-group\"> <a class=\"list-group-item active\" href=\"#\">$this->projectName <p class=\"pull-right\">Due Date: $re_projectStartDate</p></a> <div class=\"list-group-item \" > Project Name: $this->projectName</br> Project Type: $this->projectType</br> Project Owner: $this->projectOwner</br> Project Team: <a href=\"$this->projectTeam\">$this->projectTeam</a></div> </div> ";