/    Sign up×
Community /Pin to ProfileBookmark

Php Pagination Links Not Displaying

Php Folks,

I need to create pagination.

I am struggling as I in a mess …

[code]
$i = 0;
while($i<$max_pages)
{
if($i<$max_pages)
{
echo “<a href=”$_SERVER[‘PHP_SELF’];”;?>?form_type=<?php echo $_SESSION[‘form_type’];?>&query_type=<?php echo $_SESSION[‘query_type’];?>&form_step=end&page_limit=1&page=<?php echo $i;?>”><?php echo $i;?></a><?php
}
elseif($i==$page_number)
{
echo “<a href=”$_SERVER[‘PHP_SELF’];?>?form_type=<?php echo $_SESSION[‘form_type’];?>&query_type=<?php echo $_SESSION[‘query_type’];?>&form_step=end&page_limit=1&page=<?php echo $i;?>”><?php echo “<b>$i<b>”;?></a><?php
}
elseif($i>=$max_pages)
{
echo “<a href=”$_SERVER[‘PHP_SELF’];?>?form_type=<?php echo $_SESSION[‘form_type’];?>&query_type=<?php echo $_SESSION[‘query_type’];?>&form_step=end&page_limit=1&page=<?php echo $previous_page;?>”><?php echo “<b>Previous Page<b>”;?></a><?php
//session_destroy();
}
$i++;
}
[/code]

So you should see pagination numbered page links like so …

1 2 3 4 5

If you’re on page 4 then that should be displayed as bold.
When you are in final page, you see no page numbered links but a link that says:

Previous Page

These codes ain’t working:

[code]
if($i<$max_pages)
{
echo “<a href=”$_SERVER[‘PHP_SELF’];”;?>?form_type=<?php echo $_SESSION[‘form_type’];?>&query_type=<?php echo $_SESSION[‘query_type’];?>&form_step=end&page_limit=1&page=<?php echo $i”>$i</a>;
}
[/code]

Parse error: syntax error, unexpected ” (T_ENCAPSED_AND_WHITESPACE), expecting ‘-‘ or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

[code]
if($i<$max_pages)
{
echo “<a href=”$_SERVER[‘PHP_SELF’];”;?>?form_type=<?php echo $_SESSION[‘form_type’];?>&query_type=<?php echo $_SESSION[‘query_type’];?>&form_step=end&page_limit=1&page=<?php echo “$i”>$i</a>”;
}
[/code]

Parse error: syntax error, unexpected ” (T_ENCAPSED_AND_WHITESPACE), expecting ‘-‘ or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

How would you code it ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorJun 10.2020 — Tried these. Not working:

1.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href=";?&gt;'&lt;?php echo $_SERVER['PHP_SELF'];?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;'&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '?' in C:xampphtdocspower.pagesearch_3.php on line 1155

2.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href='";?&gt;&lt;?php echo $_SERVER['PHP_SELF'];?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;'&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '?' in C:xampphtdocspower.pagesearch_3.php on line 1155

3.
<i>
</i>if($i&lt;$max_pages)
{
echo '&lt;a href="$_SERVER['PHP_SELF']';?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;"&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected 'PHP_SELF' (T_STRING), expecting ',' or ';' in C:xampphtdocspower.pagesearch_3.php on line 1155

I don't think the above number 3 is valid anyway. But still tried.

4.
<i>
</i>if($i&lt;$max_pages)
{
echo '&lt;a href=';?&gt;&lt;php echo $_SERVER['PHP_SELF']';?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;'&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1159

5.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href="$_SERVER['PHP_SELF']";?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;"&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

6.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href='$_SERVER['PHP_SELF']";?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;'&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

7.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href='$_SERVER['PHP_SELF']";?form_type=&lt;?php echo $_SESSION['form_type'];?&gt;&amp;query_type=&lt;?php echo $_SESSION['query_type'];?&gt;&amp;form_step=end&amp;page_limit=1&amp;page=&lt;?php echo $i;?&gt;'&gt;&lt;?php echo $i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

8.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href="$_SERVER['PHP_SELF'];?form_type=$_SESSION['form_type']&amp;query_type=$_SESSION['query_type']&amp;form_step=end&amp;page_limit=1&amp;page=$i"&gt;$i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

9.
<i>
</i>if($i&lt;$max_pages)
{
echo "&lt;a href='$_SERVER['PHP_SELF'];?form_type=$_SESSION['form_type']&amp;query_type=$_SESSION['query_type']&amp;form_step=end&amp;page_limit=1&amp;page=$i'&gt;$i;?&gt;&lt;/a&gt;&lt;?php
}

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocspower.pagesearch_3.php on line 1155

No luck! 9 attempts!

Let's see you make one attempt and get it to work! ;)
Copy linkTweet thisAlerts:
@developer_webauthorJun 10.2020 — @NogDog,

@Sempervivum,

@ginerjm,

I'd like to see how you folks would write it.

Pagination urls are something like these:

http://localhost/power.page/search_3.php?form_type=search&query_type=select&form_step=start&page_limit=1&page=2

http://localhost/power.page/search_3.php?form_type=search&query_type=select&form_step=start&page_limit=1&page=3

The differences are at the end: "page=".

And so on.

Cheers!
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...