Php 只回显数据库行的值
我在从数据库行获取值时遇到了一点问题。我有一个数据库连接正常的页面。我想要的是使用类似于Php 只回显数据库行的值,php,mysql,Php,Mysql,我在从数据库行获取值时遇到了一点问题。我有一个数据库连接正常的页面。我想要的是使用类似于的方法从特定行回显值,其中$value是以下代码: $sql = "SELECT * FROM assortiment WHERE Id = 11481"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each
的方法从特定行回显值,其中$value
是以下代码:
$sql = "SELECT * FROM assortiment WHERE Id = 11481";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["Fotomateriaal"];
}
} else {
echo "No results";
}
为什么??因为使用这段代码输出:72157634651630294
。这就是我想要得到的价值。但我想以类似
的形式使用它,因为我试图在这段代码中使用它:
echo do_shortcode( '[slickr-flickr id="21@XXX" search="sets" set="' . $value . '" size="large" items="19" bottom="30" responsive="on" orientation="landscape" restrict="orientation" type="galleria" galleria_options="lightbox:true;thumbnail:lazy"]');
我试过:
do_shortcode( '[slickr-flickr id="21@XXX" search="sets" set="' . $sql . '" size="large" items="19" bottom="30" responsive="on" orientation="landscape" restrict="orientation" type="galleria" galleria_options="lightbox:true;thumbnail:lazy"]');
但这只是代码,而不是值。你喜欢这个工作吗?此代码不起作用
$sql = "SELECT * FROM assortiment WHERE Id = 11481";
echo $row["Fotomateriaal"];
我希望我清楚地表明了我要做什么。这里有点难以解释 您可以将查询结果存储在变量中,稍后在代码中使用
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$value = $row["Fotomateriaal"];
}
} else {
$value = "No results";
}
现在在
$value
中,查询返回了记录。我假设只返回一行。您最近的示例不起作用,因为您既没有执行查询,也没有获取任何数据 您可以将查询结果存储在变量中,稍后在代码中使用
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$value = $row["Fotomateriaal"];
}
} else {
$value = "No results";
}
现在在
$value
中,查询返回了记录。我假设只返回一行。您最近的示例不起作用,因为您既没有执行查询,也没有获取任何数据 回显不会显示整行,它是回显单个项目。。您必须使用var\u dump/print\r是否必须将其分配给变量而不是回显<代码>echo$行[“fotomaterial”]代码>==>$value=$row[“fotomaterial”]
(虽然如果您只是期望一个结果,您不需要在的同时使用,
)循环它,只需执行$value=$row[“fotomaterial”]代码>而不是echo$row[“fotomaterial”]代码>回显不会显示整行,它将回显单个项目。。您必须使用var\u dump/print\r是否必须将其分配给变量而不是回显<代码>echo$行[“fotomaterial”]代码>==>$value=$row[“fotomaterial”]
(虽然如果您只是期望一个结果,您不需要在的同时使用,
)循环它,只需执行$value=$row[“fotomaterial”]代码>而不是echo$row[“fotomaterial”]代码>哇,就是这样。。谢谢我不得不添加$sql=“SELECT*fromscholdiment,其中Id=11481”$结果=mysqli_查询($conn,$sql)代码>但它可以工作!万分感谢。哇,就是这样。。谢谢我不得不添加$sql=“SELECT*fromscholdiment,其中Id=11481”$结果=mysqli_查询($conn,$sql)代码>但它可以工作!非常感谢。