Gossamer Forum
Home : General : Internet Technologies :

PHP Span...

Quote Reply
PHP Span...
I'm trying to create a span page routine in PHP, so that the results can be spread out of several pages. I have the following code;

Code:
// here is where we create the toolbar, with links ... ie. 1 | 2 | 3 | 4 | 5 | 6
function generate_toolbar($entries,$page_num) {

$pages = 0;

$pages = $entries / 5;

for ($i =0; $i <= $pages; $i++) {
$page_count++;
}

echo "Entries: $entries Pages: $pages PageNum: $page_num \$page_count = $page_count<BR>";


// go through and actually generate the HTML for the span...
for ($i = 1; $i <= $page_count; $i++) {

echo "\$i = $i <BR>";

echo "$page_num == $i <BR>";

// if its the page number, then dont link, otherwise create a link to that page..
if ($page_num == "$i") {
$_pages .= "<font face=Tahoma size=2 color=black>+$i</font> | ";
} else {
$_pages .= "<a href=\"index.php?action=guest_list&page=$i\">";
$_pages .= "<font face=Tahoma size=2 color=black>_$i</font></a> | ";
}

} // end the 'for'

return $_pages;

}

The above code produces the following output;

Quote:
Entries: 7 Pages: 1.4 PageNum: 1 $page_count = 2
$i = 1
1 == 1
$i = 2
1 == 2
Toolbar pages: +1 | +2 |

As you can see, the last 'if' statement seems to match no matter what. Even thought the 4th and 6th lines obviously show that the values should only match on one of the 'if' statements.

Can anyone see why it is doing this? I'm totally stumped Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] PHP Span... In reply to
seemed to work ok for me, called with $pages = generate_toolbar(7, 1);

---------- PHP ----------
Content-type: text/html; charset=iso-8859-1
X-Powered-By: PHP/4.3.2

Entries: 7 Pages: 1 PageNum: 1 $page_count = 2<BR>
$i = 1 <BR>
1 == 1 <BR>
$i = 2 <BR>
1 == 2 <BR>
<font face=Tahoma size=2 color=black>+1</font> | <a href="index.php?action=guest_list&page=2"><font face=Tahoma size=2 color=black>_2</font></a> |
Output completed (0 sec consumed) - Normal Termination
Quote Reply
Re: [Mark Badolato] PHP Span... In reply to
I found the problem. I was using;

Code:
// generate the span pages stuff...
$page = $on_page || 1

but I needed to use;

Code:
// generate the span pages stuff...
$page = $on_page;
if (!$page) { $page = 1; }

Does PHP not supoort the || function?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] PHP Span... In reply to
RTFM

http://uk2.php.net/...nguage.operators.php
Quote Reply
Re: [Andy] PHP Span... In reply to
In Reply To:
Does PHP not supoort the || function?

Not in that context (like Perl does), which pisses me off a lot of time :)
Quote Reply
Re: [Mark Badolato] PHP Span... In reply to
Drop php for perl, then you won't be pissed off =)
Quote Reply
Re: [Mark Badolato] PHP Span... In reply to
Well, in PHP you could use:

$page || $page = 1;

or if you wanted to check for zero values as well, you could use:

isset($page) || $page = 1;

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [Paul] PHP Span... In reply to
In Reply To:
Drop php for perl, then you won't be pissed off =)

If only I could. Working for a Fortune 500 company with a PHP site requires that you program in PHP :)