使用if / elseif语句的require语句 [英] using require statments with if/elseif statements
问题描述
Hello有没有办法编写if / elseif语句来使用require语句显示多个php页面。我目前正在使用rss从博客收集文章并在网页上显示链接。如何根据从mysql数据库中选择的数组值显示某个提要。对不起,这很多,希望我能很好地解释我的问题。以下是显示页面上的代码:
Hello is there a way to write if/ elseif statements to display multiple php pages using require statements. I am currently collecting articles from blogs using rss and displaying the links on a web page. How can I display a certain feed depending on an array value selected from a mysql database. Sorry this is a lot, hope I explained my question well. Here is the code on the display page:
$query = "SELECT interests FROM signup WHERE username = '$username'";
$result = mysql_query($query) or die ("no query");
$result_array = array();
while($row = mysql_fetch_array($result))
{
$result_array[] = $row['interests'];
} if ($result_array[0] = Politics) {
require 'politics.php';
}
推荐答案
你有一个 =
并且未引用政治。改变你的最后几行看起来像这样:
You have a single =
and Politics isn't quoted. Change you last few lines to look like this:
if ($result_array[0] == 'Politics') {
require 'politics.php';
}
另外,作为附注,你应该确保正确地逃避<查询变量中的code> $ username ,以防止SQL注入攻击。
Also, as a side note, you should be sure to correctly escape the $username
in your query variable to prevent SQL injection attacks.
这篇关于使用if / elseif语句的require语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!