2017-01-15 1 views
0

반환 된 SQL 쿼리를 기반으로 새 테이블을 표시하려고합니다. 이것은 사용자가 페이지를로드 할 때 표시되는 원래 테이블 코드입니다.결과 테이블 표시 SQL

표는 :

<form action="walkthroughs.php" method="POST"> 
     Platform: <input type="text" name="platform"/><br/> 
     <input type="submit" value="Search"/> 
</form> 
<body> 
    <section class="container"> 
     <div class="row"> 
      <table id="table1" class="table table-bordered"> 
       <thead> 
        <th>ID</th> 
        <th width="25%">FAQ Title</th> 
        <th width="25%">Game</th> 
        <th width="*">Platform</th> 
        <th width="15%">Date Created</th> 
        <th width="15%">Date Modified</th> 
       </thead> 
       <tbody> 
        <?php 
         mysql_connect("localhost", "root", "password") or die(mysql_error()); //Connect to server 
         mysql_select_db("walkthroughs") or die("Cannot connect to database"); //connect to database 
         $query = mysql_query("Select * from faqlist"); // SQL Query 
         while($row = mysql_fetch_array($query)) 
         { 
          Print "<tr>"; 
           Print '<td align="center">'. $row['FAQ_ID'] . "</td>"; 
           Print '<td align="center">'. $row['FAQ_Title'] . "</td>"; 
           Print '<td align="center">'. $row['Game'] . "</td>"; 
           Print '<td align="center">'. $row['Platforms'] . "</td>"; 
           Print '<td align="center">'. $row['Date_Created'] . "</td>"; 
           Print '<td align="center">'. $row['Date_Modified'] . "</td>"; 
          Print "</tr>"; 
         } 
        ?> 
       </tbody> 
      </table> 
     </div> 
    </section> 
</body> 

이것은 내가 실행하기 위해 노력하고있어 PHP 코드입니다. (내 </html> 태그의 바닥에 배치.)

PHP : 내가 다른 테이블을 추가하고 을 숨기지 않고 ID "표"와 HTML 테이블을 업데이트하려면 어떻게

<?php 
    if($_SERVER["REQUEST_METHOD"] == "POST") // Added an if to keep the page secured 
    { 
     $platform = mysql_real_escape_string($_POST['platform']); 

     mysql_connect("localhost", "root", "password") or die(mysql_error()); // Connect to server 
     mysql_select_db("walkthroughs") or die("Cannot connect to database"); // Connect to database 
     $query = mysql_query("SELECT FAQ_ID, FAQ_Title, Game, Platforms FROM faqlist WHERE 
Platforms LIKE '$platform' OR Platforms LIKE '%$platform' OR Platforms LIKE '$platform%' OR Platforms LIKE '%$platform%'"); // SQL Query 
     while($row = mysql_fetch_array($query)) 
     { 
      Print "<tr>"; 
       Print '<td align="center">'. $row['FAQ_ID'] . "</td>"; 
       Print '<td align="center">'. $row['FAQ_Title'] . "</td>"; 
       Print '<td align="center">'. $row['Game'] . "</td>"; 
       Print '<td align="center">'. $row['Platforms'] . "</td>"; 
      Print "</tr>"; 
     } 
    } 
    else 
    { 
     header("location: walkthroughs.php"); 
    } 
?> 

" table1 " 테이블? 나는 현재 PHP로 시작하고있다.

+3

때마다 [은'mysql_'] (http://stackoverflow.com/questions/12859942/why-shouldnt- i-use-mysql-functions-in-php) 새 코드 데이터베이스 확장 ** [새끼 고양이는 세계 어딘가에서 교살 된 상태입니다.] (http://2bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg /AS6XCd6aNdg/s1600/luna_getting_strangled.jpg) * 그것은 더 이상 사용되지 않으며 수년간 계속되었으며 PHP7에서 영원히 사라졌습니다. PHP를 배우려는 분이라면'PDO' 또는'mysqli' 데이터베이스 확장과 prepared statement를 배우는 데 많은 시간을 할애하십시오. [여기에서 시작] (http://php.net/manual/en/book.pdo.php) – RiggsFolly

+3

스크립트에 [SQL 주입 공격] 위험이 있습니다 (http://stackoverflow.com/questions/60174/how -in-prevent-sql-injection-in-php) [Little Bobby Tables] (http://bobby-tables.com/)에 무슨 일이 있었는지 살펴 보자. [입력을 이스케이프하고 있다면 안전하지!] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) [준비된 매개 변수가있는 문] (http://php.net /manual/en/mysqli.quickstart.preparedstatements.php) – RiggsFolly

+0

첫 번째 쿼리가 처리 된 후 코드 명을 '' – RiggsFolly

답변

0

이 확장은 PHP 5.5.0에서 더 이상 사용되지 않으며 PHP 7.0.0에서 제거되었습니다. 대신 MySQLi 또는 PDO_MySQL 확장을 사용해야합니다.

동일한 논리에서 다른 예를 공유합니다.

<?php 
$con=mysqli_connect("localhost","my_user","my_password","my_db"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; 
$result=mysqli_query($con,$sql); 

// Numeric array 
$row=mysqli_fetch_array($result,MYSQLI_NUM); 
printf ("%s (%s)\n",$row[0],$row[1]); 

// Associative array 
$row=mysqli_fetch_array($result,MYSQLI_ASSOC); 
printf ("%s (%s)\n",$row["Lastname"],$row["Age"]); 

// Free result set 
mysqli_free_result($result); 

mysqli_close($con); 
?> 

결과

필수. mysqli_query() mysqli_store_result() 또는 mysqli_use_result (의해 반환 된 결과 집합 식별자)

선택

RESULTTYPE를 지정한다. 생성해야 할 배열 유형을 지정합니다. 다음 값 중 하나 일 수 있습니다

MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH, 사용

+0

테이블을 인쇄합니까? –

+0

매우 간단한 조작으로 인쇄 할 수 있습니다. –

관련 문제