2011-12-01 3 views
2

나는 등급 유형 시스템을 만들고 데이터베이스의 행 수를 기준으로 카운트 쿼리를 드롭 다운에 넣으려고했습니다. 나는 배율을 반환하려고합니다. 예 : 1-5mysql 데이터를 사용하여 드롭 다운 넣기

<?php 
// Ruth Gammack 

session_start(); 
$page = 'index.php'; 
mysql_connect('localhost', 'root', '') or die(mysql_error()); 
mysql_select_db('group4') or die(mysql_error()); 
//echo "Done"; 


    require_once "./includes/choices.inc.php"; 
    if(isset($_GET["action"])){ 
     switch($_GET["action"]) { 
      case "add": 
       addmodule(); 
       break; 

      case "remove": 
       removemodule(); 
       break; 

      case "empty": 
       emptychoice(); 
       break; 
     } 
     reviewChoices(); 
     // close database connection 
     dbClose($conn); 
    } 



function modules(){ 
    $get = mysql_query('SELECT * FROM module'); 
    if (mysql_num_rows($get) == 0){ 
     echo '<p>There are no Modules available at this time please check back later</p>'; 
    } 

    else { 

     while ($get_row = mysql_fetch_assoc($get)) { 
     echo '<p>'.$get_row['moduleID'].'<br />'.$get_row['ModuleName'].'<br />'.$get_row['ModuleDesc'].'<br />'.$get_row['LecturerID'].'</p>'; 
     // printing the list box select command 
     $query_disp=('SELECT moduleID, COUNT(*) FROM module'); 
     $result_disp = mysql_query($query_disp); 
     echo "<select name=”selRating”>"; 

     while($row = mysql_fetch_array($result_disp)) 
     { 
     echo "<option value='" . $row['moduleID'] . "'>" . $row['moduleID'] . "</option>"; 
     /* Option values are added by looping through the array */ 
     } 
     echo "</select>";// Closing of list box 

     } 

    } 

} 

?> 

나는 여러 가지 방법으로 시도했지만 아이디어가 부족합니다.

답변

0

어쩌면 이런 식으로 테스트 한 것입니까?

$query_disp=('SELECT moduleID, ModuleName, ModuleDesc, LecturerID, COUNT(*) AS cnt FROM module GROUP BY moduleID'); 
$select = "<select name=”selRating”>"; 
while($row = mysql_fetch_array($query_disp)) 
{ 
    echo '<p>'.$get_row['moduleID'].'<br />'.$get_row['ModuleName'].'<br />'.$get_row['ModuleDesc'].'<br />'.$get_row['LecturerID'].'</p>'; 
    $select += "<option value='" . $row['moduleID'] . "'>" . $row['ModuleName'] . " " . $row['cnt'] . "</option>"; 
} 
$select += '</select>';  

echo $select; 
관련 문제