double0201 2014-12-29 20:55
浏览 16

PHP从模板创建新页面

I already have a function where you can insert data to the database which then prints out all the "item_name"s on the index with their respective "item_name" as url (example.com/example_name)

To dumb the code down lets say item_name is the only row I have, and I want each item to have it's own page that says "My item: example_name". Here is the code I'm currently using for printing the list of items:

<?php 
    $sql = "SELECT * FROM items ORDER BY item_name DESC";
    $result = $conn->query($sql);


if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
         echo '        
         <p>
            <a href="/' . $row["item_name"] . '"> ' . $row["item_name"] . ' </a>
         </p> ';      

    }
} else {
    echo "0 results";
}
$conn->close();
?>

What is the simplest way to go about doint this? Security is no big issue here. Sorry if duplicate question, I have searched for over 2 hours now without finding anything directly applying to my issue. I am pretty new to programming in general so please don't go very technical on me. Thank you.

  • 写回答

2条回答 默认 最新

  • dongyinju5977 2014-12-29 21:13
    关注

    If what you want is to create a page while reading the contents of your DB, you'd have to first read the name from the DB (you already did that), and then create/write the file in each iteration (within the loop). That'd create a file per name.

    Here you have examples on how to create/write a file easily using php. Of course, there are many ways of doing this.

    Be sure that the user with which you're running the script has enough permissions to write on the server. Hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c