Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    PHP code help please

    The code below is from the shopping cart software I use. It produces the navigational links in this format:

    Pages: 1 | 2 | 3 | 4 | 5 | 6 | 7 >> 11

    I would prefer it not to trim/compress the links so they are like this
    Pages: 1 | 2 | 3 | 4 | 5 | 6 | 7 |8|9|10|11|, etc, etc

    Any idea if it the PHP code that is causing the compression??

    Code:
    <?php
    
    $eol          = $this->globals('khxc.eol');
    
    $ovarray      = $this->globals('khxc.sorttable');
    $navarray     = $this->globals('khxc.navarray');
    
    $dispapp      = $this->globals('khxc.app');
    $dispns       = $this->globals('khxc.namespace');
    $reference    = $ovarray['table']['tid'];
    
    $dbrelactive  = $this->globals('khxc.dbrelate_active');
    
    // +--
    // | Modify our some of our vars if we have an active dbrelate
    // | function being executed.
    // +--
    
    if ($dbrelactive) {
    
         $dispns    = 'dbrelate';
         $reference = $this->globals('khxc.dbrelate_ns');
    
    } // End of if statement.
    
    $link_func = 'dboverview';
    
    if ($this->globals('khxc.dbsearch_active')) {$link_func = 'dbsearchproc';}
    
    // +--
    // | Display navigation links if there are any.
    // +--
    
    if (!(empty($navarray))) {
    
         print '<p class="khxc_ultableh">Navigation</p>';
    
         print '<p>A total of ' . $navarray['total'] . ' items are available matching the criteria you selected.  ';
         print 'There are ' . $navarray['numpages'] . ' pages of data to view.  You are currently viewing page ';
         print $navarray['currentpg'] . ' of ' . $navarray['numpages'] . '.  Click below to navigate through ';
         print 'the entire page set.</p>';
    
         print '<div>' . $eol;
         print '<p>Pages: ' . $eol;
    
         $plinks = '';
    
         foreach ($navarray['pages'] as $link) {
    
              // +--
              // | You can use $link['link'] instead of $link['pg'] below to 
              // | show the actual result numbers rather than page numbers.
              // +--
    
              $href = $this->link_namespace($dispapp,$dispns,array('ref'    => $reference,
                                                                   'func'   => $link_func,
                                                                   'count'  => $link['count'],
                                                                   'offset' => $link['offset']));
    
              if ($link['type'] == 'LAST') {
                   if (preg_match('/ \| $/',$plinks)) {$plinks = rtrim($plinks,' | ');}
                   $plinks .= ' &gt;&gt; ';
              }
    
              if ($link['current']) {
    
                   $plinks .= $link['pg'];
    
              } else {
    
                   $plinks .= '<a href="' . $href . '" title="Page ' . $link['pg'] . ' of ' . $navarray['numpages'] . '">';
                   $plinks .= $link['pg'] . '</a>';
    
              } // End of if statement.
    
              if ($link['type'] == 'FIRST') {$plinks .= ' &lt;&lt; ';}
              else {$plinks .= ' | ';}
    
         }
    
         if (preg_match('/ \| $/',$plinks)) {$plinks = rtrim($plinks,' | ');}
    
         print $plinks;
    
         print '</p>' . $eol;
         print '</div>' . $eol;
    
    } // End of if navarray statement.
    
    ?>
    Thanks
    Rob

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't know how this code even works, its out of an object scope but has frequent calls to $this. Any any case, you need to post the code for a function called 'dboverview'.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks
    The code for dboverview is:
    Code:
    <?php
    
    $eol          = $this->globals('khxc.eol');
    
    $ovarray      = $this->globals('khxc.sorttable');
    $navarray     = $this->globals('khxc.navarray');
    
    $dispapp      = $this->globals('khxc.app');
    $dispns       = $this->globals('khxc.namespace');
    
    $dbrelactive  = $this->globals('khxc.dbrelate_active');
    
    $lastsql     = $this->xhtml_encode($this->globals('khxc.sorttable_sqllast'));
    
    // +--
    // | Print custom header text if defined.
    // +--
    
    if (!(empty($ovarray['custom_text']))) {
    
         print '<p>' . $this->xhtml_encode($ovarray['custom_text']) . '</p>' . $eol . $eol;
    
    } // End of if statement.
    
    // +--
    // | Print instructions.
    // +--
    
    if (!($dbrelactive)) {
    
         print '<p>This interface is used to manage the items stored in the database table 
                associated with this function.  Depending on the permissions associated with 
                this table, you may have options to insert data (add a new item), update 
                data (change the values for an item), delete data (remove an item), clone 
                data (make a copy of an item) and to search for items matching particular 
                criteria.</p>';
    
    } // End of if statement.
    
    // +--
    // | Define $menulinks.
    // +--
    
    $menulinks = $ovarray['menulinks'];
    
    // +--
    // | Delete our menulinks if we have an active dbrelate
    // | function being executed.
    // +--
    
    if ($dbrelactive) {
    
         $menulinks = array();
    
    } // End of if statement.
    
    // +--
    // | Print the functions menu if $menulinks is defined.
    // +--
    
    if (!(empty($menulinks))) {
    
         print '<p class="khxc_ultableh">Functions Menu</p>';
    
         foreach ($menulinks as $id => $linkarray) {
    
              $xurl  = $linkarray['url'];
              $xlink = $this->xhtml_encode($linkarray['link']);
              $xid   = $id;
    
              print '<p class="khxc_ultablei"><a href="' . $xurl . '" title="';
              print $xid . '">';
              print $xlink . '</a></p>' . $eol;
    
         } // End of foreach statement.
    
    } // End of if statement.
    
    // +--
    // | Display navigation if we need to.
    // +--
    
    if (!(empty($navarray))) {
    
         $this->include_file('khxc','dbnav.php');
    
    } // End of if not empty navarray.
    
    if ((empty($navarray)) && ($ovarray['total_count'])) {
    
         print '<p class="khxc_ultableh">Navigation</p>';
    
         print '<p>A total of ' . $ovarray['total_count'] . ' items are available matching the criteria you selected.  All items are presented on this page.</p>' . $eol;
    
    } // End of if statement.
    
    // +--
    // | If there are no items to display...
    // +--
    
    if (!($ovarray['total_count'])) {
    
         if ($this->globals('khxc.dbsearch_active')) {
    
              print '<p class="khxc_ultableh">Search Results</p>' . $eol;
    
              print '<p>Currently there are no items in the database to display that match your search criteria.</p>' . $eol;
    
         } else {
    
              print '<p class="khxc_ultableh">Data Overview</p>' . $eol;
    
              print '<p>Currently there are no items in the database to display.</p>' . $eol;
    
         } // End of if statement.
    
    // +--
    // | If there are items to display...
    // +--
    
    } else {
    
         // +--
         // | Print the heading.
         // +--
    
         if ($this->globals('khxc.dbsearch_active')) {
    
              print '<p class="khxc_ultableh">Search Results</p>';
    
         } else {
    
              print '<p class="khxc_ultableh">Data Overview</p>';
    
         } // End of if statement.
    
         // +--
         // | Print the table opener.
         // +--
    
         print '<table id="' . $dispapp . '--maindata" class="khxc_sorttable">' . $eol;
    
         // +--
         // | Print the table headers.
         // +--
    
         print '<tr class="khxc_sorttable">' . $eol;
    
         $headers      = $ovarray['headers'];
         $headers_wurl = $ovarray['headerswurl'];
    
         foreach ($headers as $id => $display) {
    
              print '<th class="khxc_sorttable">' . $this->xhtml_encode($display) . '</th>' . $eol;
    
         } // End of foreach statement.
    
         print '</tr>' . $eol;
    
         // +--
         // | Print the table data.
         // +--
    
         $data    = $ovarray['data'];
         $trclass = 'khxc_sorttablep';
    
         foreach ($data as $num => $row) {
    
              $dbrellink = 0;
    
              print '<tr class="' . $trclass . '">' . $eol;
    
              foreach ($headers as $id => $display) {
    
                   print '<td class="' . $trclass . '">';
    
                   if (array_key_exists($id,$headers_wurl)) {
    
                        if (preg_match('/^http/',$row[$id])) {
    
                             $print_header = $this->xhtml_encode($headers[$id]);
    
                             print '<a href="' . $row[$id] . '" class="khxc_sorttable" title="';
                             print $print_header . '">' . $print_header . '</a>';
    
                        } else {
    
                             print $row[$id];
    
                        } // End of if statement.
    
                   } else {
    
                        if (!($row[$id] === '')) {print $this->xhtml_encode($row[$id]);} else {print '&nbsp;';}
    
                   } // End of if statement.
    
                   print '</td>' . $eol;
    
              } // End of foreach statement.
    
              print '</tr>' . $eol;
    
              if ($trclass == 'khxc_sorttablep') {$trclass = 'khxc_sorttablea';}
              else {$trclass = 'khxc_sorttablep';}
    
         } // End of foreach statement.
    
         // +--
         // | Print the table closure.
         // +--
    
         print '</table>' . $eol;
    
    } // End of if total_count.
    
    // +--
    // | Display navigation if we need to (again).
    // +--
    
    if (!(empty($navarray))) {
    
         $this->include_file('khxc','dbnav.php');
    
    } // End of if not empty navarray.
    
    // +--
    // | Delete our lastsql if we have an active dbrelate
    // | function being executed.
    // +--
    
    if ($dbrelactive) {
    
         $lastsql = '';
    
    } // End of if statement.
    
    // +--
    // | Print the SQL statement submitted if it's defined.
    // +--
    
    if ($lastsql) {
    
         print '<p class="khxc_ultableh">Database Information: SQL Statement Submitted</p>' . $eol . $eol;
    
         print '<p class="khxc_ultablesql">' . $lastsql . '</p>' . $eol . $eol;
    
    } // End of if statement.
    
    ?>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This is the weirdest way I've ever seen code put together, very difficult to follow. Its like importing file code into parts of objects. Can you also post the code for dbsearchproc? I missed the ternary call.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Many Thanks

    You pointed me in the right direction and I have found what I needed.

    Rob

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Hey thats great!
    Sometimes all it takes is a fresh pair of eyes to see where you need to look. I spent three hours debugging a script the other day before passing it onto a buddy who's first question is '... um, where is the include call for you're object?'. Oops, lol, should have followed my own advice - error_reporting baby, lol.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •