2013-09-27 133 views
-6

我不擅長PHP中的函數和類。我回應函數而不是回報,因爲它給了我想要的結果。但它也會將結果值回顯到我想要的頁面。這個功能在課堂上。只要看到這個screenshot,你就會明白我想要什麼。回聲PHP函數或返回?

回聲出總數:

<?php 

echo $results->get_total_marks_subjects($subject_detail['subject_id']); 

?> 

這裏是類函數代碼:

while($rec = mysql_fetch_array($link)) { 
     //i think the code below echoes out that message. 
     echo $rec['total_marks']." | "; 
     //return $rec['total_marks']; 
    } 
}  
+1

什麼是日問題?我不在這裏看到任何功能! –

+0

我沒有發佈全功能代碼,因爲問題是我在函數中回顯值而不是返回。只要看到圖像,然後你就會得到我想要的。 – user1313942

+0

只是評論回聲,你會得到你想要的 – user4035

回答

0

我會想你想要什麼......

我假設當它通過一個mysql對象的結果時,它會多次echo $ rec ['total_marks']。而不是

<?php echo $results->get_total_marks_subjects($subject_detail['subject_id']); ?> 

嘗試:

<?php 
    $_results=$results->get_total_marks_subjects($subject_detail['subject_id']); 
    foreach ($_results as $_result) { 
     echo $_result; 
    } 
?> 

與其使用:

 while($rec = mysql_fetch_array($link)) { 
     echo $rec['total_marks']." | "; i think, this code echo out that message. 
     //return $rec['total_marks']; 
     } 

嘗試:

 $_tempcounter=0; 
    while($rec = mysql_fetch_array($link)) { 
     $arrayofresults[$_tempcounter++] = $rec['total_marks']; 
     } 
    return $arrayofresults; 
+0

感謝您的回答......但可悲的是,它不工作......它使我的頁面變爲空白......您的代碼中可能存在問題。 – user1313942

+0

我無法通過使用php找到解決方案,但通過使用CSS來隱藏這些值。目前,它正在工作。感謝您的回覆。 – user1313942