gpt4 book ai didi

php - 如何打印数据

转载 作者:行者123 更新时间:2023-11-29 16:47:34 25 4
gpt4 key购买 nike

这是我的代码,但它运行时没有任何结果,我有一个表“ slider ”,其中包含图像的 id 和 URL,我确信 connect.php 没问题。

<?php
$sliders=array();
include"connect.php";
$query_getinfo="select * from sliders";
$result=$connect->prepare($query_getinfo);
$result->execute();

while($row=$result->fetch(PDO:: FETCH_ASSOC)){
$record=array();
$record["id"]=$row["id"];
$record["slide_url"]=$row["slide_url"];

$slider[]=$record;

//$sliders[]=$row["slide_url"];

}

print_r ($sliders);

?>

最佳答案

看起来您没有任何参数要传递,因此您可以将准备替换为查询并删除执行,下面是 2 个示例

如果要传递参数

// prepare the query
$sliders = array();

$statement = $connect->prepare("select * from sliders WHERE type = ?");

// assuming type is string eg admin / user

$statement->bind_param("s", $_SESSION['type']);
// execute it
$statement->execute();

// ger result
$result = $statement->get_result();

// check if rows exists in table
if($result->num_rows > 0){

while($row = $result->fetch_assoc()) {
$record=array();
$record["id"]=$row["id"];
$record["slide_url"]=$row["slide_url"];
$sliders[]=$record;
}

print "<pre";
print_r($sliders);

}else{
print "no sliders found";
}

$statement->close();

如果查询中没有参数

$sliders = array();

// prepare the query

$result = $connect->query("select * from sliders");

// check if rows exists in table
if($result->num_rows > 0){

while($row = mysqli_fetch_assoc($result)) {
$record=array();
$record["id"]=$row["id"];
$record["slide_url"]=$row["slide_url"];
$sliders[]=$record;
}

print "<pre";
print_r($sliders);

}else{
print "no sliders found";
}

// if you want to close connection here.
$connect->close();

关于php - 如何打印数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53012407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com