我试图从我的数据库中的列回合中获得“回合”的值。所以,我想要获得每个辩论/帖子的一个字段值。基于价值/数量,它应该显示不同的东西。当我认为它的值为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);
}
}
}
?>
不确定您为什么使用所有'if'。你最好使用这样简单的代码:$ result = mysql_query(“SELECT rounds FROM vf_Discussion”); ($ row = mysql_fetch_array($ result)) echo $ row ['column']; .... } – mele
@mele,仍然不起作用。 – julereca