用php和mysqli自动创建新页面 [英] automatically create new pages with php and mysqli

查看:69
本文介绍了用php和mysqli自动创建新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仍然需要学习php和mysqli,还有很多东西要学习,但是在这一点上,这个问题是我最重要的优先事项之一.

still getting my feet wet with php and mysqli, have so much to learn, but at this point this question is one of my most important priorities.

我对此问题进行了一些研究,但老实说,目前我的水平已经不胜枚举.我想找到一种最简单,最有效的方法,以自动"生成大量的页面,每个页面中包含不同的数据.

I did some research about this issue but am currently overwhelmed by pretty sophisticated stuff for my level, to be honest. I'd like to find the simplest most efficient way to "automatically" generate a great number of pages each with varying data in it.

下面的页面1的代码示例非常简化,因为实际的页面实际上还有很多东西,但是希望简化的示例可以说明我的观点.

the example of page 1's code below is extremely simplified, because the actual page actually has a lot more stuff, but the simplified example serves, I hope, to make my point.

<?php

$servername = "servername";
$username = "username";
$password = "password";
$db= "db";

$conn = mysqli_connect("servername","username","password","db");


$query = "SELECT word FROM demo WHERE group=1";
$result = $conn->query($query);
$row = mysqli_fetch_assoc($result);
$word = $row['word'];

echo $word;

?>

在我的表中,组"列中有/将有500个条目(记录?),编号为1、2、3等,一直到500. 对于我的特定目的,我绝对需要创建与组一样多的在线页面-在此示例中,为500个页面.

in my table I have / would have something like 500 entries (records?) in the 'group' column, numbered 1, 2, 3 etc all the way to 500. for my specific purpose, I absolutely need to create as many online pages as there are groups -- in this example, 500 pages.

第2页的回声必须引用第2组,第3页的回声必须引用第3组,依此类推.

page 2's echo would have to refer to group 2, page 3's echo would have to refer to group 3, and so on.

很显然,有一种方法可以做到,无需复制和粘贴代码500次,也无需手动更改每次!哈哈.但是最简单的方法是什么?

obviously, there's a way to do this without copying and pasting the code 500 times and manually changing the group in each! haha. but what's the simplest way?

预先感谢您的理解和帮助,无论哪种方式,祝您度过愉快的一天.

thank you in advance for any understanding and help, and either way, have an awesome day.

推荐答案

如果我对您的理解正确,我相信您正在等待动态地从数据库创建页面.您可以在请求http://yoursite.com/page.php?group=1.中使用get变量 然后在您的代码中更新查​​询以执行以下操作:

If I'm understanding you correctly, I believe you're waiting to create pages from the database Dynamically. You can use a get variable in the request http://yoursite.com/page.php?group=1. Then in your code update your query to do:

$query = "SELECT word FROM demo WHERE group=".$_GET['group'];

该查询是不安全的,因为任何用户都可以将原始mysql注入$ _GET ['group']变量中.

That query is insecure, as any user could inject raw mysql into the $_GET['group'] variable.

$group = mysqli_real_escape_string($conn, $_GET['group']);
$query = "SELECT word FROM demo WHERE `group`='$group'";

这更安全.

这篇关于用php和mysqli自动创建新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆