我在profile.php中有这段代码:
$table_to_paginate = 'updates';
$posts_per_page = 5;
require_once ("pagination/start_pagination.php");
$query = "SELECT * FROM updates ";
$query .= " ORDER BY id DESC ";
$query .= " LIMIT {$start}, {$posts_per_page}";
在包含的文件中,即' pagination / start_pagination.php'我有这些代码:
//max displayed per page
$per_page = $posts_per_page;
//get start variable
if(isset($_GET['start'])) {
$start = $_GET['start'];
}
//count records
if(!isset($additional_info)){$additional_info = NULL;}
$counting = "SELECT * FROM {$table_to_paginate}";
$counting .= "{$additional_info}";
$record_count = mysql_num_rows(mysql_query($counting));
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if (!isset($start)) {
if(isset($upsidedown)){
if($record_count - $per_page < 0 ){ $start = 0;} else {$start = $record_count - $per_page;}
} else {
$start = 0;
}
}
问题是,include可以找到该文件,但它不提供包含文件中的变量,以便我可以在profile.php中使用它。有趣的是,它适用于localhost,但是当我将它上传到服务器时,它不起作用。
其他信息:我需要包含文件的$ start。
答案 0 :(得分:0)
如果要跨文件边界使用变量,则需要通过$GLOBALS
数组访问变量:
// in profile.php
$query .= " LIMIT {$GLOBALS['start']}, {$posts_per_page}";
// in start_pagination.php
$per_page = $GLOBALS['posts_per_page'];
// ... snip
$counting = "SELECT * FROM {$GLOBALS['table_to_paginate']}";