...

View Full Version : PHP code help please



robbiez
07-17-2008, 08:03 PM
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??


<?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

Fou-Lu
07-17-2008, 08:18 PM
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'.

robbiez
07-17-2008, 08:25 PM
Thanks
The code for dboverview is:

<?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.

?>

Fou-Lu
07-17-2008, 08:36 PM
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.

robbiez
07-17-2008, 09:11 PM
Many Thanks

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

Rob

Fou-Lu
07-17-2008, 09:41 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum