gpt4 book ai didi

php - 动态创建包含不同数据的个人资料页面

转载 作者:行者123 更新时间:2023-11-29 10:46:26 25 4
gpt4 key购买 nike

我有一个名为艺术家的mySQL表,索引页面包含所有艺术家姓名的列表,我希望用户单击艺术家的姓名进入包含艺术家数据的个人资料页面,因此php将创建个人资料基于个人资料模板和艺术家 ID 的页面,而不是为每个艺术家创建数百个页面,我该怎么做

编辑:获取php页面代码

<?php
include("config.php"); //include config file
//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);

//throw HTTP error if page number is not valid
if(!is_numeric($page_number)){
header('HTTP/1.1 500 Invalid page number!');
exit();
}

//get current starting point of records
$position = (($page_number-1) * $item_per_page);

//fetch records using page position and item per page.
$results = $mysqli->prepare("SELECT name, location, score, img FROM artists ORDER BY score DESC LIMIT ?, ?");

//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
//for more info https://www.sanwebe.com/2013/03/basic-php-mysqli-usage
$results->bind_param("ss", $position, $item_per_page);
$results->execute(); //Execute prepared Query
$results->bind_result($name, $location, $score, $img); //bind variables to prepared statement

//output results from database

while($results->fetch()){ //fetch values
echo "<a href=<div class=\"feed_item\">";
echo "<img src=\"img/" . $img . ".jpg\"class=\"feed_img\">";
echo "<h2 class=\"feed_title\">" . $name . "</h2>";
echo "<h4 class=\"feed_subtitle\">" . $location . "</h4>";
echo "</div>";
}
?>

我的表格中有 ID 列,我感到迷失,不知道在 google/here 中搜索什么。

最佳答案

如果您提供一些代码来显示您当前如何查询数据库以获取所有艺术家的列表,那么我们将能够为您提供更多帮助。

一般来说,您需要做的是执行查询,然后循环遍历每个结果。在循环中,您需要设置一个指向 artist.php?id=XX 的链接,其中 XX 是循环中特定艺术家的 ID。

然后,您可以创建一个名为 artist.php 的新脚本,该脚本具有一个查询来获取 GET 请求中发送的 ID。

例如

select * from artists where id='$id' 

然后您可以执行此查询,获取该艺术家的结果,然后在屏幕上显示详细信息。

这是一个高层次的内容,但希望能让您了解需要采取的方法。

关于php - 动态创建包含不同数据的个人资料页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44485649/

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