0
我想從我的數據庫中的列回合得到「回合」的價值。所以,我想爲每個辯論/帖子獲得一個字段的值(1-5)。基於價值/數量,它應該顯示不同的東西。當我認爲它的值爲NULL時,即使該辯論/帖子的db字段值是4.這不僅僅是辯論,但是對於所有這些都會發生。如何獲得列中字段的實際值並將其分配給名爲$ rounds的變量。這個變量需要具有每次辯論的價值,而不僅僅是辯論。從每個字段的列中獲取值,但它返回NULL?
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
$con = new mysqli($servername, $username, $password, $dbname);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
else{
$sql = "SELECT rounds FROM vf_Discussion";
$result = $con->query($sql);
$allRounds = $result->fetch_row();
$rounds = $allRounds[0];
var_dump($rounds);
}
mysqli_close($con);
$rounds1 = '<h2 class="CommentHeading">Round 1 (Pro)</h2> <br> <h2 class="CommentHeading">Round 1 (Con) </h2>';
$rounds2 = '<h2 class="CommentHeading">Round 2 (Pro)</h2> <br> <h2 class="CommentHeading">Round 2 (Con)</h2>';
$rounds3 = '<h2 class="CommentHeading">Round 3 (Pro)</h2> <br> <h2 class="CommentHeading">Round 3 (Con)</h2>';
$rounds4 = '<h2 class="CommentHeading">Round 4 (Pro)</h2> <br> <h2 class="CommentHeading">Round 4 (Con)</h2>';
$rounds5 = '<h2 class="CommentHeading">Round 5 (Pro)</h2> <br> <h2 class="CommentHeading">Round 5 (Con)</h2>';
foreach($allRounds as $rounds) {
if ($rounds == 1) {
echo $rounds1;
foreach ($Sender->Data('Answers') as $Row) {
$Sender->EventArguments['Comment'] = $Row;
WriteComment($Row, $Sender, Gdn::Session(), 0);
}
}
if ($rounds == 2) {
echo $rounds1;
echo $rounds2;
foreach ($Sender->Data('Answers') as $Row) {
$Sender->EventArguments['Comment'] = $Row;
WriteComment($Row, $Sender, Gdn::Session(), 0);
}
}
if ($rounds == 3) {
echo $rounds1;
echo $rounds2;
echo $rounds3;
foreach ($Sender->Data('Answers') as $Row) {
$Sender->EventArguments['Comment'] = $Row;
WriteComment($Row, $Sender, Gdn::Session(), 0);
}
}
if ($rounds == 4) {
echo $rounds1;
echo $rounds2;
echo $rounds3;
echo $rounds4;
foreach ($Sender->Data('Answers') as $Row) {
$Sender->EventArguments['Comment'] = $Row;
WriteComment($Row, $Sender, Gdn::Session(), 0);
}
}
if ($rounds == 5) {
echo $rounds1;
echo $rounds2;
echo $rounds3;
echo $rounds4;
echo $rounds5;
foreach ($Sender->Data('Answers') as $Row) {
$Sender->EventArguments['Comment'] = $Row;
WriteComment($Row, $Sender, Gdn::Session(), 0);
}
}
}
?>
的可能的複製[正從列中的值,而是返回null?](https://stackoverflow.com/questions/44574090/getting-the-迭代value-from-column-but-returns-null) – Phil