2014-04-26 60 views
0

我有一個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> 
        "; 

    } 
+0

http://www.php.net/manual/en/function.str-split.php – underscore

+1

你不能使用嵌套一個標籤 –

回答

0

您可以值,而像 回聲想這呼應的變量

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> 
        "; 
+0

謝謝,但數值仍然被認爲是一個鏈接。 – user3470172

+0

告訴我結果 –

+0

嘗試回聲$ projectOwner的東西嗎? –

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> ";