2012-10-10 2 views
-1

제 질문은 : 왜 내 MySQL 데이터가 테이블에 표시되지 않습니까? 모든 것은 내 데이터 (새 이름 등의 목록)가 나타나지 않는다는 점을 제외하면 잘 작동하는 것 같습니다. 내 실수가 어디 있는지 알 수있는 신선한 눈이 필요해. 그리고 네, 아마이 일을하는 더 쉬운 방법이 있다는 것을 압니다.하지만 이것은 제 임무에 필요한 것이므로 다른 일을하지 마십시오. 필요한 것은 HTML 테이블에 데이터를 채우는 것입니다. 내 PHP 코드는 다음과 같습니다, 제이슨 감사 :내 테이블에 내 MySQL 데이터가 표시되지 않는 이유는 무엇입니까?

PHP 코드 " 내부 같은 에코

<?php 
    $pageTitle = 'Mod06 Pagination| Jason McCoy '; 
    include('includes/header.inc.php'); 
    include ('includes/db_connect.inc.php'); 

    $display = 8; 

    // Determine how many pages there are... 

    if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined. 
     $pages = $_GET['pages']; 
    } else { 
     $query = "SELECT COUNT(birdID) FROM birds"; 
     $result = @mysqli_query($dbc, $query); 
     $row = @mysqli_fetch_array($result, MYSQLI_NUM); 
     $records = $row[0]; 
    } 

    // Calculate the number of pages... 

    if ($records > $display) { 
     $pages = ceil($records/$display); 
    } else { 
     $pages = 1; 
    } 

    // Determine where in the database to start returning results... 

    if (isset($_GET['s']) && is_numeric($_GET['s'])) { 
     $start = $_GET['s']; 
    } else { 
     $start = 0; 
    } 

    // Sort the columns 
    // Default is birdID 

     $sortDefault = 'birdID'; 

     // Create an array for the columns 

     $sortColumns = array('birdID', 'nameGeneral', 'nameSpecific', 'populationTrend'); 

     // Define sortable query ASC DESC 

     $sort = (isset($_GET['sort'])) && in_array($_GET['sort'], $sortColumns) ? $_GET['sort']: $sortDefault; 
     $order = (isset($_GET['order']) && strcasecmp($_GET['order'], 'DESC') == 0) ? 'DESC' : 'ASC'; 

     // Run the query 

    $query = "SELECT birdID, nameGeneral, nameSpecific, populationTrend FROM birds ORDER BY $order LIMIT $start, $display"; 
    $result = @mysqli_query($dbc, $query);  
?> 

    <!-- Table header: --> 
    <table align="center" cellspacing="0" cellpadding="5" width="80%"> 
     <tr> 
      <th><a href='index.php?sort=birdID&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Bird<? 
          if($_GET["order"]=="ASC" && $_GET["sort"]=="birdID"){ 
           echo '<img src="images/downArrow.jpg" id="birdASC" name="birdASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
          } else { 
        echo '<img src="images/upArrow.jpg" id="birdDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
       }?></a></th> 
      <th><a href='index.php?sort=nameGeneral&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>General Name<? 
          if($_GET["order"]=="ASC" && $_GET["sort"]=="nameGeneral"){ 
           echo '<img src="images/downArrow.jpg" id="nameGeneralASC" name="nameGeneralASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
          } else { 
        echo '<img src="images/upArrow.jpg" id="nameGeneralDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
       }?></a></th> 
      <th><a href='index.php?sort=nameSpecific&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Name Specific<? 
          if($_GET["order"]=="ASC" && $_GET["sort"]=="nameSpecific"){ 
           echo '<img src="images/downArrow.jpg" id="nameSpecificASC" name="nameSpecificASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
          } else { 
        echo '<img src="images/upArrow.jpg" id="nameSpecificDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
       }?></a></th> 
      <th><a href='index.php?sort=populationTrend&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Population Trend<? 
          if($_GET["order"]=="ASC" && $_GET["sort"]=="populationTrend"){ 
           echo '<img src="images/downArrow.jpg" id="populationTrendASC" name="populationTrendASC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
          } else { 
        echo '<img src="images/upArrow.jpg" id="populationTrendDESC" name="birdDESC" style="margin:-15px 0 0 13px;" width="18px" height="18px">'; 
       }?></a></th> 
     </tr> 
<?php 

    // Display the database results in the table... 

    while ($row = @mysqli_fetch_array($result, MYSQL_ASSOC)) { 
     echo '<tr> 
      <td align="left">$row[birdID]</td> 
      <td align="left">$row[nameGeneral]</td> 
      <td align="left">$row[nameSpecific]</td> 
      <td align="left">$row[populationTrend]</td> 
     <tr>'; 
    } 

    echo '</table>';  
    mysqli_close($dbc); 

    // Make the links to other pages, if necessary. 
    if ($pages > 1) { 
     echo '<br /><p>'; 
     $currentPage = ($start/$display) + 1; 
    // If it's not the first page, make a Previous button: 
    if ($currentPage != 1) { 
     echo '<a href="index.php?s=' . ($start - $display) . '&pages=' . $pages . '&sort=' . $sort . '">Previous</a> '; 
    } 
    // Make all the numbered pages: 
    for ($i = 1; $i <= $pages; $i++) { 
     if ($i != $currentPage) { 
      echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&pages=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; 
     } else { 
      echo $i . ' '; 
     } 
    } // End of FOR loop. 

    // If it's not the last page, make a Next button: 
    if ($currentPage != $pages) { 
     echo '<a href="index.php?s=' . ($start + $display) . '&pages=' . $pages . '&sort=' . $sort . '">Next</a>'; 
    } 

    echo '</p>'; 

} 

    include('includes/footer.inc.php'); 
?> 


</div> 
</body> 
</html> 

답변

0

는 변경 모든 $row['birdID']이 하나 $row[birdID], 당신은 ''를 놓쳤다.

+0

도움을 주셔서 감사하지만 작동하지 않는다면 오류가 발생합니다. – HoppedUpDesigns

+0

어떤 오류가 발생하고 있습니까? –

+0

현재 표시되는 내용을 보려면 페이지 링크를 참조하십시오. http://www.jasonkmccoy.com/AB-Tech/web250/Mod06/McCoy_mod06/index.php?sort=nameSpecific&order=ASC 오류 구문 분석 오류 : 예기치 않은 T_ENCAPSED_AND_WHITESPACE 구문 오류, T_STRING 또는 T_VARIABLE 또는 T_NUM_STRING이 /home/jkm1972/public_html/AB-Tech/web250/Mod06/McCoy_mod06/index.php on line 92에 있음을 나타냅니다. – HoppedUpDesigns

0

사용, 당신은 때문에 데이터베이스에서 값이 표시되지 않았는지의 '을 사용했다.

while ($row = @mysqli_fetch_array($result, MYSQL_ASSOC)) { 
    echo "<tr> 
     <td align=\"left\">$row[birdID]</td> 
     <td align=\"left\">$row[nameGeneral]</td> 
     <td align=\"left\">$row[nameSpecific]</td> 
     <td align=\"left\">$row[populationTrend]</td> 
    <tr>"; 
} 
0

죄송합니다 ... 전화에서 입력, 조금 간결 경우

'$ 행 [birdID]'

과 다른 부분이 제대로으로 다시 작성해야합니다

'$ 행 [ 'birdID'] '

birdID는 문자열이며 변수 이름이 아닙니다.

PHP는 현재 범위에 해당 이름의 변수가없는 경우이 문자열을 문자열로 사용하지만. PHP는 문서에서

Always use quotes around a string literal array index. For example, $foo['bar'] is correct, while $foo[bar] is not. But why? It is common to encounter this kind of syntax in old scripts

: http://php.net/manual/en/language.types.array.php

편집 사람이 너무 에코에 사용되는 작은 따옴표를 지적, 그건 너무 문제입니다. 작은 따옴표를 사용하면 PHP는 문자열의 내용을 해석하지 않고 큰 따옴표를 사용하면 PHP가 구문 분석을 수행하고 값을 올바르게 사용합니다.

+0

당신의 말을 이해하지만 제안하지 않았다. – HoppedUpDesigns

+0

나는 생각했다. MySQL은 ** 소문자 테이블 이름과 열 이름만을 사용 했는가? 'birdID'대신 'birdid'로 시도해보십시오. 슬프게도, 지금 당장이 테스트를 수행 할 MySQL이 없습니다. 또한 MySQL Workbench 또는 PHPMyAdmin에서 쿼리 자체를 실행하십시오. – ppeterka

+0

데이터가 올바르게 표시되지만 정렬이 작동하지 않습니다. – HoppedUpDesigns

관련 문제