2015-06-25 65 views
0

我該如何將css應用到$row["name"]並將其顯示在表格中?
這裏是我的代碼:php數據庫顯示在網頁

<div class="maincontent1"> 
       <?php 
       $link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link)); 
       $sql = "SELECT id, name, description1 FROM table1"; 
       $result = $link->query($sql); 
       if ($result->num_rows > 0) 
        { 
        // output data of each row 
       while($row = $result->fetch_assoc()) 
         { 

        ?> 
          <div class="title-style1"> 
          <?php 
           echo $row["name"]; 
          ?> 
          </div>  
        <?php 
         echo $row["description1"]; 
         } 
         $link->close(); 
        } 
         ?> 
+0

*如何給css $ row [「name」] * - 什麼'css'?要在'table'中打印它們,只需要相應地替換'div'。 –

+0

請解釋你需要什麼輸出。 –

回答

0

我不清楚你說的關於CSS什麼,但如果你想你的數據在表格打印,那麼你可以做這樣的事情

<table>  
     <tr> 

      <th> 
       Name 
      </th> 
      <th> 
       Description 
      </th> 
     </tr> 
    <?php 
         $link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link)); 
         $sql = "SELECT id, name, description1 FROM table1"; 
         $result = $link->query($sql); 
         if ($result->num_rows > 0) 
          { 
          // output data of each row 
         while($row = $result->fetch_assoc()) 
        { 
        ?> 
           <tr> 
            <div class="title-style1"> 
           <td>  <?php 
             echo $row["name"]; 
            ?> 

           </td> 
          <td> 
            <?php 
             echo $row["description1"]; 
            ?> 
          </td> 
         </div> 
          </tr> 
          <?php 
           } 
           $link->close(); 

          } 
           ?> 
    </table> 
0

爲了可以嘗試這樣的事:

<div class="maincontent1"> 
      <?php 
        $link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link)); 
        $sql = "SELECT id, name, description1 FROM table1"; 
        $result = $link->query($sql); 
        if ($result->num_rows > 0) { 
      ?> 
     <div class="title-style1"> 
     <table name="table" border: 1px solid black ; cellspacing='0'> 
      <thead> 
       <tr> 
        <th style= "" > Name </th> // you can put the style you want here 
        <th style= "" > Description </th> 
       </tr> 
      </thead> 
       <?php while($row = $result->fetch_assoc()){ ?> 
         <td style=""> <?php echo $row['name'];?></td> //style here 
         <td style=""> <?php echo $row['description1'];?></td> //style here 

        <?php 
         } 

        ?> 
     </table> 
<?php } 
    $link->close(); 
?> 

,如果你想可以只是有一個外部CSS所以你只需要調用它。我希望這有幫助。