Re: how to get rid of that annoying |

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
>
>
> PJ wrote:
>> Robert Cummings wrote:
>>> PJ wrote:
>>>> Robert Cummings wrote:
>>>>> PJ wrote:
>>>>>> I know this a silly question, but I can't figure out if it's even
>>>>>> possible to get rid of that final annoying | in my pagination
>>>>>> script.
>>>>>>
>>>>>> <?echo "<p>Navigation</p>";
>>>>>>
>>>>>> echo (($page !=1)?"<a href='".build_url("books.php", "page",
>>>>>> 1)."'>first</a>":"first")." ... ";
>>>>>> echo (($page>1)?"<a href='".build_url("books.php", "page",
>>>>>> $page-1)."'>prev</a>":"prev")." | ";
>>>>>> for($i=$page; $i<=($page+$records_per_page-2)+1; $i++){
>>>>>>   if ($i!=$page && $i<ceil($count/$records_per_page))
>>>>>>     echo "<a href='".build_url("books.php", "page",
>>>>>> $i)."'>$i</a>", "
>>>>>> | ";
>>>>>>   elseif ($i>ceil($count/$records_per_page))
>>>>>>     continue;
>>>>>>   else echo $i, " | ";
>>>>>> }
>>>> ---------------|
>>>>>> echo " | ... ".(($page<$count)?"<a href='".build_url("books.php",
>>>>>> "page", $page+1)."'>next</a>":"next");
>>>>>> echo "  ... ".(($page<$count)?"<a href='".build_url("books.php",
>>>>>> "page",
>>>>>> ceil($count/$records_per_page))."'>last</a>":"last");
>>>>>> //echo "<p>Table Order</p>";
>>>>>> echo "<br />Ordered alphabetically by book title : ";
>>>>>> echo $dir=="ASC"?"Ascending":"<a href='".build_url("books.php",
>>>>>> "dir",
>>>>>> "asc")."'>Ascending</a>";
>>>>>> echo " | ";
>>>>>> echo $dir=="DESC"?"Descending":"<a href='".build_url("books.php",
>>>>>> "dir",
>>>>>> "desc")."'>Descending</a>";
>>>>>> echo "<br />";?>
>>>>>>
>>>>>> This produces a very nifty pagination - the problem is how to get
>>>>>> rid of
>>>>>> the final pages that show up as greater than what is available. The
>>>>>> script above works fine, except it leaves that final | ...
>>>>>> Any simple solutions?
>>>>>>
>>>>> Do it differently... build an array of the appropriate entries. When
>>>>> done, use implode( ' | ', $yourArray ).
>>>>>
>>>>> Cheers,
>>>>> Rob.
>>>> Hate to disappoint you all, but I finally found the errant | .
>>>> Ridiculous, really, that I bothered you all.
>>>> it's in the line indicated above --- echo " | ... " --- lose the | and
>>>> it all works like a charm.
>>>>
>>>> :-)     ;-)
>>> You didn't disappoint me... I've seen code like that before, I just
>>> thought you'd benefit from a cleaner approach instead of the above
>>> mess.
>> Actually, as I am new to this, I still have another little glitch which
>> is a pita. Oh, I know it's a bit of a mess; I have a hard time
>> following, myself. But, being lazy, I'm trying to fix thigs with a
>> band-aid. :-(
>>
>> But I don't understand how I would "build an array of the appropriate
>> entries"... what entries do you mean?
>
> You have links, each separated by the pipe '|' character. Add each
> link to a links array:
>
> <?php
>
>     $links = array();
>     foreach( $items as $item )
>     {
>         $links[] = '<a href="#">'.$item.'</a>';
>     }
>
>     echo implode( ' | ', $links );
>
> ?>
>
> Hope that helps.
I'm afraid I still don't understand. I think you are seeing something
that I don't see. What do you mean by link in the present context... are
you talking about some snippet of code equaling each page or every page
in the db? This is an ever growing db.

Anyway, I finally found the error of my ways (at least in this code). It
may look sloppy, but then I haven't looked that hard for other examples.
Some I found were too simple, others too bloated.
At least, this one works for what I need and does exactly what I wanted.
:-)
Here's the final fixed code; some obvious (I hope) variables are left
out and precede the code:

echo (($page !=1)?"<a href='".build_url("books.php", "page",
1)."'>first</a>":"first")." ... ";
echo (($page>1)?"<a href='".build_url("books.php", "page",
$page-1)."'>prev</a>":"prev")." | ";
for($i=$page; $i<=($page+$records_per_page-2)+1; $i++){
  if ($i>ceil($count/$records_per_page))
    continue;
  elseif ($i!=$page)
    echo "<a href='".build_url("books.php", "page", $i)."'>$i</a>", " | ";
  else
    echo $i, " | ";
}
echo " ... ".(($page<ceil($count/$records_per_page))?"<a
href='".build_url("books.php", "page", $page+1)."'>next</a>":"next");
if ($page==ceil($count/$records_per_page))
  echo " ... last";
elseif ($i!=ceil($count/$records_per_page)) echo "  ...
".(($page<ceil($count/$records_per_page)+$records_per_page)?"<a
href='".build_url("books.php", "page",
ceil($count/$records_per_page))."'>last</a>":"last");
else echo "  ... ".(($page<$count)?"<a href='".build_url("books.php",
"page", ceil($count/$records_per_page))."'>last</a>":"last");
echo "<br>Ordered alphabetically by book title : ";
echo $dir=="ASC"?"Ascending":"<a href='".build_url("books.php", "dir",
"asc")."'>Ascending</a>";
echo " | ";
echo $dir=="DESC"?"Descending":"<a href='".build_url("books.php", "dir",
"desc")."'>Descending</a>";

If there is a way to simplify things, please do let me know (with an
example, please)
PJ



-- 
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux