2016-04-15 18 views
1

私はスクリプトで数時間座っていますが、正しく動作しません。ブートストラップテーブルにmysqlデータを書きたいと思います。残念ながら、私はいつも他の情報やエラーメッセージを出します。 誰かがこのスクリプトを見ることができれば非常にいいです。PHP、Mysql、Bootstrapテーブルが動作しない

$conn = new mysqli($servername, $username, $password, $dbname); 
$conn->set_charset("utf8"); 
$sql = "SELECT Osman, Tanja, Christiane, Marcella, Magarita, Nathalie, Kommentar, Gutschein, EC FROM Salon1_10_04_2016"; 
$results = $conn->query($sql); 

<table class="table table-hover"> 
    <thead> 
    <tr> 
    <th>Firstname</th> 
    <th>Lastname</th> 
    <th>Email</th> 
    </tr> 
</thead> 
<tbody> 
     <?while($row = mysqli_fetch_assoc($result)) { 
      echo"<tr class='table_row'>"; 
      echo"<td>" . $row['Osman'] . "</td>"; 
      echo"<td>" . $row['Tanja'] . "</td>"; 
      echo"<td>" . $row['Christiane'] . "</td>"; 
      echo"<td>" . $row['Marcella'] . "</td>"; 
      echo"<td>" . $row['Magarita'] . "</td>"; 
      echo"<td>" . $row['Nathalie'] . "</td>"; 
      echo"<td>" . $row['Kommentar'] . "</td>"; 
      echo"<td>" . $row['Gutschein'] . "</td>"; 
      echo"<td>" . $row['EC'] . "</td>"; 
      echo"</tr>"; 
      } echo"</table>";}?> 
+0

:チェックしたい場合は、値を使用すると、値が空の場合は希望のcharを返すための簡単な関数を定義することができ、文字列の中にあります["fields_count"] => int ["lengths"] => NULL ["num_rows"] => [num_rows] => > int(1)["type"] => int(0)} –

+0

スクリプトの途中で2番目のPHPタグ '<?'を開いた理由は? – mitkosoft

+0

この2つの間に、htmlとcssスクリプトがあります。 whileループで –

答えて

1

あなたは手続き型でオブジェクト指向のスタイルを混合され、これを試してみてください:

<?php 
$conn = new mysqli($servername, $username, $password, $dbname); 
$conn->set_charset("utf8"); 
$sql = "SELECT Osman, Tanja, Christiane, Marcella, Magarita, Nathalie, Kommentar, Gutschein, EC FROM Salon1_10_04_2016"; 
$results = $conn->query($sql); 
?> 
<table class = "table table-hover"> 
    <thead> 
     <tr> 
      <th>Firstname</th> 
      <th>Lastname</th> 
      <th>Email</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
     while ($row = $results->fetch_assoc()) { 
      echo"<tr class='table_row'>"; 
      echo"<td>" . $row['Osman'] . "</td>"; 
      echo"<td>" . $row['Tanja'] . "</td>"; 
      echo"<td>" . $row['Christiane'] . "</td>"; 
      echo"<td>" . $row['Marcella'] . "</td>"; 
      echo"<td>" . $row['Magarita'] . "</td>"; 
      echo"<td>" . $row['Nathalie'] . "</td>"; 
      echo"<td>" . $row['Kommentar'] . "</td>"; 
      echo"<td>" . $row['Gutschein'] . "</td>"; 
      echo"<td>" . $row['EC'] . "</td>"; 
      echo"</tr>"; 
     } 
     ?> 
    </tbody> 
</table> 

とにかくテーブル本体の列の数は、あなたのSQLが有効であることを確認して、thead要素で定義されているよりも、切り抜いたです。

UPDATE:私は実際には$結果、私からのvar_dumpを作るとき

<?php 
function checkNull($str){ 
    if(!trim($str)) return '-'; 
    else return $str; 
} 

// how to use it: 
echo"<td>" . checkNull($row['Osman']) . "</td>"; 
?> 
+0

それは、ありがとう! あなたは、mysqlフィールドにNULLが表示されたときに、どのように表示することができますか? これは最後の考えであり、スクリプトが実行されたものです。 –

+0

はい、更新をチェックしてください – mitkosoft

関連する問題