2017-11-12 15 views
0

私はこのlinkで解決策を模倣しようとしていますが、失敗しています。私の目的は、SQLデータベースからデータをインポートしてhtmlテーブルに入れて、CSSを使用してテーブルの外観を修正できるようにすることです。誰かが私を助けてくれますか?SQLデータベースのデータをphp/htmlテーブルに表示

ありがとうございます。 code.Yourの問題以下の

コード

<?php 

$mysqli = NEW mysqli('localhost','username','password','database'); 

require('/home/database/public_html/wp-load.php'); 
$id = get_the_ID(); 

$resultSet = $mysqli->query("SELECT * FROM sweepstake_data WHERE item_id = $id"); 

if($resultSet->num_rows !=0){ 

echo "<table>"; // start a table tag in the HTML 

    while($rows = $resultSet->fetch_assoc()) 
    { 
     $description = $rows['description']; 
     $links = $rows['links']; 
     $category = $rows['category']; 
     $eligibility = $rows['eligibility']; 
     $start_date = $rows['start_date']; 
     $end_date = $rows['end_date']; 
     $entry_frequency = $rows['entry_frequency']; 
     $prizes = $rows['prizes']; 
     $victory_prizes = $rows['victory_prizes']; 
     $additional_comments = $rows['additional_comments']; 

     "<tr><td>" . echo $description != "" ? "<p>Name: $description<br />" : "" ; 
     "<tr><td>" . echo $links != "" ? "Link: <a href=$links>Click here</a> <br />" : "" ; 
     "<tr><td>" . echo $category != "" ? "Category: $category<br />" : "" ; 
     "<tr><td>" . echo $eligibility != "" ? "Eligibility: $eligibility<br />" : "" ; 
     "<tr><td>" . echo $start_date != "" ? "Start date:$start_date<br />" : "" ; 
     "<tr><td>" . echo $end_date != "" ? "End date: $end_date<br />" : "" ; 
     "<tr><td>" . echo $entry_frequency != "" ? "Entry frequency: $entry_frequency<br />" : "" ; 
     "<tr><td>" . echo $prizes != "" ? "Prizes: $prizes<br />" : "" ; 
     "<tr><td>" . echo $victory_prizes != "" ? "Victory prizes: $victory_prizes<br />" : "" ; 
     "<tr><td>" . echo $additional_comments != "" ? "Additional comments: $additional_comments<br />" : "" ; 

    } 

echo "</table>"; //Close the table in HTML 

}else { 
    echo "No results."; 
} 

?> 
+0

私が最初にあなたがそれについて見てしまう – Strawberry

+0

@Strawberry必ず用意し、結合したクエリについての参照をお勧めしたいです。私は確かに詳細を読むだろうが、クイック検索はSQLインジェクションの危険性を明らかにする?私のコードが影響を受けやすいと示唆していますか?ありがとうございました。 – firefirehelphelp

答えて

0

使用は

<?php 

$mysqli = NEW mysqli('localhost','username','password','database'); 

require('/home/database/public_html/wp-load.php'); 
$id = get_the_ID(); 

$resultSet = $mysqli->query("SELECT * FROM sweepstake_data WHERE item_id = $id"); 

if($resultSet->num_rows !=0){ 

echo "<table>"; // start a table tag in the HTML 

    while($rows = $resultSet->fetch_assoc()) 
    { 
     $description = $rows['description']; 
     $links = $rows['links']; 
     $category = $rows['category']; 
     $eligibility = $rows['eligibility']; 
     $start_date = $rows['start_date']; 
     $end_date = $rows['end_date']; 
     $entry_frequency = $rows['entry_frequency']; 
     $prizes = $rows['prizes']; 
     $victory_prizes = $rows['victory_prizes']; 
     $additional_comments = $rows['additional_comments']; 

     echo "<tr><td>"; 
     $description != "" ? "<p>Name: $description<br />" : "" ; 
     echo "<tr><td>"; 
     echo $links != "" ? "Link: <a href=$links>Click here</a> <br />" : "" ; 
     echo "<tr><td>"; 
     echo $category != "" ? "Category: $category<br />" : "" ; 
     echo "<tr><td>"; 
     echo $eligibility != "" ? "Eligibility: $eligibility<br />" : "" ; 
     echo "<tr><td>" ; 
     echo $start_date != "" ? "Start date:$start_date<br />" : "" ; 
     echo "<tr><td>" ; 
     echo $end_date != "" ? "End date: $end_date<br />" : "" ; 
     echo "<tr><td>"; 
     echo $entry_frequency != "" ? "Entry frequency: $entry_frequency<br />" : "" ; 
     echo "<tr><td>"; 
     echo $prizes != "" ? "Prizes: $prizes<br />" : "" ; 
     echo "<tr><td>"; 
     echo $victory_prizes != "" ? "Victory prizes: $victory_prizes<br />" : "" ; 
     echo "<tr><td>"; 
     echo $additional_comments != "" ? "Additional comments: $additional_comments<br />" : "" ; 

    } 

echo "</table>"; //Close the table in HTML 

}else { 
    echo "No results."; 
} 

?> 
+0

これはうまくいった!ご協力いただき誠にありがとうございます。 – firefirehelphelp

+0

あなたの歓迎...... –

0

使用値を印刷して、通常の代わりにクエリを作成しました。

このコードは動作します:

<?php 

$mysqli = NEW mysqli('localhost','username','password','database'); 

require('/home/database/public_html/wp-load.php'); 
$id = get_the_ID(); 

$resultSet = $mysqli->prepare("SELECT * FROM sweepstake_data WHERE item_id=?"); 
$resultSet->bind_param('i',$id); 
$resultSet->execute(); 
$result = $resultSet->get_result(); 


if($result->num_rows !=0){ 

echo "<table>"; // start a table tag in the HTML 

while($rows = $result->fetch_assoc()) 
{ 
    $description = $rows['description']; 
    $links = $rows['links']; 
    $category = $rows['category']; 
    $eligibility = $rows['eligibility']; 
    $start_date = $rows['start_date']; 
    $end_date = $rows['end_date']; 
    $entry_frequency = $rows['entry_frequency']; 
    $prizes = $rows['prizes']; 
    $victory_prizes = $rows['victory_prizes']; 
    $additional_comments = $rows['additional_comments']; 

    echo "<tr><td>"; 
    $description != "" ? "<p>Name: $description<br />" : "" ; 
    echo "<tr><td>"; 
    echo $links != "" ? "Link: <a href=$links>Click here</a> <br />" : "" ; 
    echo "<tr><td>"; 
    echo $category != "" ? "Category: $category<br />" : "" ; 
    echo "<tr><td>"; 
    echo $eligibility != "" ? "Eligibility: $eligibility<br />" : "" ; 
    echo "<tr><td>" ; 
    echo $start_date != "" ? "Start date:$start_date<br />" : "" ; 
    echo "<tr><td>" ; 
    echo $end_date != "" ? "End date: $end_date<br />" : "" ; 
    echo "<tr><td>"; 
    echo $entry_frequency != "" ? "Entry frequency: $entry_frequency<br />" : "" ; 
    echo "<tr><td>"; 
    echo $prizes != "" ? "Prizes: $prizes<br />" : "" ; 
    echo "<tr><td>"; 
    echo $victory_prizes != "" ? "Victory prizes: $victory_prizes<br />" : "" ; 
    echo "<tr><td>"; 
    echo $additional_comments != "" ? "Additional comments: $additional_comments<br />" : "" ; 

} 

echo "</table>"; //Close the table in HTML 

}else { 
echo "No results."; 
} 

?> 
+0

残念ながら、私はこれを動作させることができませんでした。助けてくれてありがとう。 – firefirehelphelp

関連する問題