News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How do I use constructPageIndex()?

Started by NanoSector, March 05, 2012, 12:52:51 PM

Previous topic - Next topic

NanoSector

Hi there :)

I decided to create a little script that allows me to have and edit a trunk full of beta releases.

Now, I think it's disturbing that you have all releases on one page. Maybe I can have a category and latest version based system but oh well, it doesn't need to be all-the-best for just an admin area. I wanted to create a page based system instead.

Now, I have this bit of code:
// What are the current downloads? (limit them to the first five)
if (!isset($_GET['download']))
{
    // Do some math.
    $count['start'] = (isset($_GET['page']) ? round($_GET['page'] * 10) : '0');
    $count['stop'] = (isset($_GET['page']) ? round($_GET['page'] * 10 + 10) : '10');
   
    $page = (isset($_GET['page']) ? $_GET['page'] : 0) + 1;
   
    // Grab our data.
    $result = $smcFunc['db_query']('',
    'SELECT id, project, version, shortdesc, file, discontinued, current
    FROM {db_prefix}trunk
    LIMIT {int:countstart}, {int:countstop}',
        array(
            'countstart' => $count['start'],
            'countstop' => $count['stop'],
        )
    );
   
    // And another one to count...
    $count = $smcFunc['db_query']('',
    'SELECT id
    FROM {db_prefix}trunk', array());
   
    $countpages = 0;
    while ($preinfo = $smcFunc['db_fetch_assoc']($result))
    {
        $downloads[] = $preinfo;
    }
    while ($count2 = $smcFunc['db_fetch_assoc']($count))
        $countpages++;
}


I'm probably doing lots of things wrong, but that's the code that counts the amount of pages.

When I add this:
$countpages = ceil($countpages / 10);
(I guess that's what I added, not sure)
it displays the right amount of pages (2 in my case for 16 entries).
As I had absolutely no idea how to make a [1] 2 etc. index of that, I decided to go with the SMF function.

I have this bit:
constructPageIndex($boardurl . '/site/beta_downloads.php', $count['start'], $count['stop'], 10, true);
and I don't understand the heck of the function.

All I get is this:
Warning: Cannot use a scalar value as an array in /home/mapcmsco/public_html/site/beta_downloads.php on line 84

EDIT:
Got it to show [1] 2. Just like that.

echo constructPageIndex($boardurl . '/site/beta_downloads.php', $_REQUEST['start'], $countpages, 10, true);

That's what I have for code.

Still, it does nothing except for standing there. When I click the 2, it does nothing and gets me to the same page.

EDIT2:
Got it to work.

Changed the previous piece of code into this:

if (isset($_GET['list']))
{
    // Do some math.
    $count['start'] = (isset($_REQUEST['start']) ? $_REQUEST['start'] : '0');
    $count['stop'] = (isset($_REQUEST['start']) ? $_REQUEST['start'] + 10 : '10');
   
    // Grab our data.
    $result = $smcFunc['db_query']('',
    'SELECT id, project, version, shortdesc, file, discontinued, current
    FROM {db_prefix}trunk
    LIMIT {int:countstart}, {int:countstop}',
        array(
            'countstart' => $count['start'],
            'countstop' => $count['stop'],
        )
    );
   
    // And another one to count...
    $count = $smcFunc['db_query']('',
    'SELECT id
    FROM {db_prefix}trunk', array());
   
    $countpages = 0;
    while ($preinfo = $smcFunc['db_fetch_assoc']($result))
    {
        $downloads[] = $preinfo;
    }
    while ($count2 = $smcFunc['db_fetch_assoc']($count))
        $countpages++;
}


and changed the other code in this:
echo 'Page: ' . constructPageIndex($boardurl . '/site/beta_downloads.php?list', $_REQUEST['start'], $countpages, 10);

Can somebody help me?
SMF version: 2.0.2
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: