我目前正在努力对网站进行一些修改。
网站目前的工作方式是页面为config.inc.php
页面调用一次require。配置页面还具有SQL调用,用于显示从数据库中显示的内容。虽然这很好用,但我需要创建一个显示同一个表的新页面,但SQL已更改为显示不同的数据。
我遇到的麻烦是config.inc.php
页面上有SQL数据,可以提供所需内容。我想在不同的页面上显示不同的结果,但网站要求config.inc.php
显示所有内容。我更改了SQL查询以测试我想要显示的内容是否有效并且它有效,但是我如何在不必使用原始SQL命令的情况下显示它。
这是原始代码;
$config = require_once 'link to admin section';
$db_username = $config['components']['db']['username'];
$db_password = $config['components']['db']['password'];
$db_link = mysql_connect('nosey', $db_username, $db_password) or die(mysql_error());
mysql_select_db('nosey', $db_link);
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
if ( isset($_GET['id']) && $_GET['id'] ) {
$selectSqlJSONString = 'SELECT * FROM vacancies WHERE id = '.$_GET['id'].' ORDER BY created ASC LIMIT 1';
$jsonResult = mysql_query($selectSqlJSONString, $db_link);
$jsonRow = mysql_fetch_object($jsonResult);
if ( !isset($_SERVER['HTTP_X_FANCYBOX']) )
include 'details_ajax_header.php';
include 'filename.php';
if ( !isset($_SERVER['HTTP_X_FANCYBOX']) )
include 'details_ajax_footer.php';
exit;
}
}
$region = '1';
if ( isset($_GET['region']) && $_GET['region'] ) {
$region .= ' AND ' . sprintf('county LIKE "%%%s%%"', mysql_real_escape_string(str_replace('-', ' ',$_GET['region']), $db_link ));
}
$selectSqlString = 'SELECT * FROM vacancies WHERE '.$region.' ORDER BY created DESC';
$result = mysql_query($selectSqlString, $db_link) or die(mysql_error());
$vacancies = array();
while ($row = mysql_fetch_object($result)) {
$vacancies[] = $row;
}
这就是我要在另一个页面上显示的内容,以显示不同的结果集。
$config = require_once 'link to admin section';
$db_username = $config['components']['db']['username'];
$db_password = $config['components']['db']['password'];
$db_link = mysql_connect('nosey', $db_username, $db_password) or die(mysql_error());
mysql_select_db('nosey', $db_link);
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
if ( isset($_GET['id']) && $_GET['id'] ) {
$selectSqlJSONString = 'SELECT * FROM vacancies WHERE id = '.$_GET['id'].' ORDER BY created ASC LIMIT 1';
$jsonResult = mysql_query($selectSqlJSONString, $db_link);
$jsonRow = mysql_fetch_object($jsonResult);
if ( !isset($_SERVER['HTTP_X_FANCYBOX']) )
include 'details_ajax_header.php';
include 'filename.php';
if ( !isset($_SERVER['HTTP_X_FANCYBOX']) )
include 'details_ajax_footer.php';
exit;
}
}
$region = '1';
if ( isset($_GET['region']) && $_GET['region'] ) {
$region .= ' AND ' . sprintf('county LIKE "%%%s%%"', mysql_real_escape_string(str_replace('-', ' ',$_GET['region']), $db_link ));
}
$selectSqlString = 'SELECT * FROM vacancies WHERE featured = "1" ORDER BY created DESC';
$result = mysql_query($selectSqlString, $db_link) or die(mysql_error());
$vacancies = array();
while ($row = mysql_fetch_object($result)) {
$vacancies[] = $row;
}
请注意我想要改变的是SELECT * FROM vacancies WHERE featured = "1"
。
这就是我所需要的!但我想包括这个,而不必改变config.inc.php
页面! (此信息来自哪里)我该怎么做?