0

データベースに接続する Web サイトを作成しています。SQL Server でデータベースを作成しました。

1 つのテーブルを 1 つの html ページに接続して、そのページでテーブルを表示できるようにします。このようにして、すべての SQL テーブルを各 html ページに接続します。

私はphp/javaqueryを使わなければならないことを知っています!

適切なコードを教えてください!

また、私はSQLが初めてです。私は学んでいます!

私のシステムでそれを有効にするためにあなたが提供したコードで私がしなければならない変更を説明してください.

私はこれらの 2 つのコードを取得しました:どちらが私の要件に適していますか? コード 1:

  $result = mysqli_query($con,"SELECT * FROM Orders");

 echo "<table>";
 echo "<table border='1'>
 <tr>
 <th>ID</th>
 <th>orderNumber</th>
 <th>Price</th>
 <th>customerName</th>
 <th>salesRep</th>
 <th>DatePicker</th>
 <th>shipMethod</th>
 <th>trackingNumber</th>
 <th>Statuscheck</th>
 <th>Edit</th>
 </tr>";

 while($row = mysqli_fetch_array($result))
   {
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['orderNumber'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['customerName'] . "</td>";
echo "<td>" . $row['salesRep'] . "</td>";
echo "<td>" . $row['DatePicker'] . "</td>";
echo "<td>" . $row['shipMethod'] . "</td>";
echo "<td>" . $row['trackingNumber'] . "</td>";
echo "<td>" . $row['Statuscheck'] . "</td>";
echo "<td>" . $row['Edit'] . "</td>";
echo "</tr>";
  }
echo "</table>";

?>

コード 2:

 <?php

   $host=""; // Host name 
   $username=""; // Mysql username 
   $password=""; // Mysql password 
   $db_name=""; // Database name 
   $tbl_name=""; // Table name 

  // Connect to server and select databse.
     mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
     mysql_select_db("$db_name")or die("cannot select DB");
     $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
  // OREDER BY id DESC is order result by descending
  }
      $result=mysql_query($sql);

    ?>

  <html>

  <head>

   <script type="text/javascript" charset="utf-8" src="jquery.js"></script>

  </head>

   <table id="forum" width="90%" border="0" align="center"          cellpadding="3"      cellspacing="1" bgcolor="#CCCCCC">

 <thead>

  <tr>
   <th width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <th width="43%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
   <th width="10%" align="center" bgcolor="#E6E6E6"><strong>Author</strong></td>
   <th width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
    <th width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
     <th width="13%" align="center"  bgcolor="#E6E6E6"><strong>Date/Time</strong></td>

     </tr>

    </thead>

    <?php 
  // Start looping table row
 while($rows=mysql_fetch_array($result)){
     ?>

  <tbody>

  <tr>
  <td bgcolor="#FFFFFF"><? echo $rows['threadtype']; ?></td>
  <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>">
  <? echo $rows['topic']; ?></a><BR></td>
 <td align="center" bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
  <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
   <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
   <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
  </tr>

  </tbody>

   <?php

   // Exit looping and close connection 
  }
   mysql_close();

  ?>

 <tfoot>
 <tr>
 <td colspan="6" align="right" bgcolor="#E6E6E6"><strong>Create New  Topic</strong> td>
</tr>
  </tfoot>
</table>

 </html>
4

1 に答える 1