duanmeng7865 2014-12-11 00:45
浏览 62
已采纳

上传到服务器时,包含文件中的代码不会执行

I have this code in 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}";

In the included file ie 'pagination/start_pagination.php' i have these codes:

//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;
            }
            }

The problem is, the include can find the file, but it doesn't provide the variables from the included file so that i can use it in profile.php. Something funny is that, It works with localhost but when i upload it to the servers it doesn't work.

additional info: I need the $start from the included file.

展开全部

  • 写回答

1条回答 默认 最新

  • douzai9405 2014-12-11 00:59
    关注

    You'll need to access the variable via the $GLOBALS array if you want to use it across file boundaries:

    // 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']}";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部