multiple pages menu not showing?
Posted: Thu Sep 03, 2009 6:54 pm
Hello all,
I'm trying to run some php script in wordpress and have implemented a plugin to allow this. Everything seems to work fine except the menu at the top of the page does not show up?
For example:
<back> 1 2 3 <next> (does not show on the page)
the code I'm using works fine on a normal php page but not in this case for some reason. I'm thinking its a simple coding error but I don't know enough about php to fix it. Can anyone help?
thanks
heres my code:
<?
//settings - please put in config.php.inc
$hostname = "";
$username = "";
$password = "";
$userstable = "";
$dbName = "";
//some additional variables we need to display pages
//number of results displayed on a page. Change this if u want...
$limit = 12;
//format-strings for the page-links
//change it to ur needs (u may add some stylesheet-information), but be aware of the %d ´s.
//They will be replaced by some values later.
//Format for a page-link, if it links not to the current result-page
$page_array_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[%d]</a> ";
//Format for a page-link, if it links to the current result-page (here it is not a link)
$page_array_format_current_page = "%d ";
//Format for the next-link
$page_next_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[next]</a> ";
//Format for the back-link
$page_back_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[back]</a> ";
//DO NOT CHANGE THIS...
//offset point. Recordsets offset+limit are displayed
$offset = (!empty($_REQUEST['offset'])) ? (int)$_REQUEST['offset'] : 0;
/**
* Function getPagesArray()
* returns Pages-Array like this:
*
* Array {
* 1 => array {
* 'page' => 1,
* 'page_offset' => 0
* }
* 2 => array {
* 'page' => 2,
* 'page_offset' => 10
* }
* }
*
*
* @return array pages-array
*/
function getPageArray($hits, $range)
{
$pages = array();
$hits = (int)$hits;
$range = (int)$range;
//if there are more hits then range allows...
if($hits > $range) {
$page_number = $hits / $range;
$number_of_pages = ceil($page_number);
$offset = 0;
for($i=1; $i<= $number_of_pages; $i++) {
$pages[$i] = array('page' => $i, 'page_offset' => $offset);
$offset += $range;
}
}
return $pages;
}
function printPageArray($hits, $range)
{
global $page_array_format, $page_array_format_current_page, $page_back_format, $page_next_format, $offset, $limit;
$offset = (int)$offset;
$hits = (int)$hits;
$pages = getPageArray($hits, $range);
//var_dump($pages);
//get the back-link
if($offset > 0) {
//if that is not the first page
//show the back-link
$back_offset = $offset - $limit;
//should not be smaller then 0
$back_offset = ($back_offset < 0) ? 0 : $back_offset;
//print formated back-link
printf($page_back_format, $back_offset);
}
//get the page-links
for($i=1; $i <= sizeof($pages); $i++) {
if($pages[$i]['page_offset'] == $offset) {
//thats the number of current page
printf($page_array_format_current_page, $pages[$i]['page']);
} else {
//not the current page
printf($page_array_format, $pages[$i]['page_offset'], $pages[$i]['page']);
}
}
//get the next-link
if(($offset + $limit) < $hits) {
//if this is not the last page
$next_offset = $offset + $limit;
printf($page_next_format, $next_offset);
}
}
//do the connection
@MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
//choose the db
@mysql_select_db( "$dbName") or die( "Unable to select database");
//first we need a simple query to get the number of all records
$query = "SELECT * FROM $userstable WHERE NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%'";
$hits = @mysql_num_rows(mysql_query($query));
//Now the real query, but now with LIMIT-Clause
$query = "SELECT PRICE,RETAILPRICE,BUYURL,NAME,DESCRIPTION,IMAGEURL,IMPRESSIONURL FROM $userstable WHERE NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%'";
$query.= " LIMIT $offset, $limit";
$result = mysql_query($query) or die(mysql_error());
/* How many of these users are there? */
$number = @mysql_num_rows($result); //FIX!!!!!!
/* Print these results to the screen in a nice format */
$i = 0;
IF ($number == 0) :
//email if no items in the category
IF ($hits == 0):
PRINT "<font size=\"2\">New Product Coming Soon!</font><br>";
$adminEmail = "";
$subject = "The category called NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%' is no longer valid";
$body = "The category NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%' no longer has products in it. Page freshwater-spinnining-reels";
mail($adminEmail,$subject,$body,"FROM: $adminEmail");
ENDIF;
ELSEIF ($number > 0) :
PRINT "";
//Now its time to print out our pages-links
PRINT "<p align=center>";
//where ever u put next line, there will be displayed the page-array
printPageArray($hits, $limit);
PRINT "</p>";
PRINT "<table width=100% border=2 cellspacing=5 cellpadding=10>";
$x = 1;
echo "<tr>";
//start inside
WHILE ($i < $number):
$PRICE = mysql_result($result,$i,"PRICE");
$BUYURL = mysql_result($result,$i,"BUYURL");
$NAME = mysql_result($result,$i,"NAME");
$DESCRIPTION = mysql_result($result,$i,"DESCRIPTION");
$IMAGEURL = mysql_result($result,$i,"IMAGEURL");
$IMPRESSIONURL = mysql_result($result,$i,"IMPRESSIONURL");
//put td here
PRINT "<td align=center width=50% valign=top>";
PRINT "<strong><font color=\"#FF0000\" size=\"2\">\$$PRICE</font></strong><BR>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><img src=$IMAGEURL border=0 width=72><BR></A>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><strong><font size=\"2\">$NAME</a></strong></font><BR>";
PRINT "<font size=\"2\" padding=10>$DESCRIPTION</font><BR><BR>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><strong><font size=\"2\">MORE...</a></strong></font><BR><BR>";
PRINT "<a href=$IMPRESSIONURL></A>";
//wrap it
//change where its 2,3,4 to 3,4,5 to display five in a row. - easy ha..
PRINT "</td>";
if ($x == 1 ) {$x ++;} else {
if ($x == 2 ) {echo "</tr><tr>"; $x=1;} else{$x ++;}
}
$i++;
ENDWHILE;
PRINT "</tr>";
echo "</table>";
//Now its time to print out our pages-links
PRINT "<p align=center>";
//where ever u put next line, there will be displayed the page-array
printPageArray($hits, $limit);
PRINT "</p>";
ENDIF;
//if is at end
?>
I'm trying to run some php script in wordpress and have implemented a plugin to allow this. Everything seems to work fine except the menu at the top of the page does not show up?
For example:
<back> 1 2 3 <next> (does not show on the page)
the code I'm using works fine on a normal php page but not in this case for some reason. I'm thinking its a simple coding error but I don't know enough about php to fix it. Can anyone help?
thanks
heres my code:
<?
//settings - please put in config.php.inc
$hostname = "";
$username = "";
$password = "";
$userstable = "";
$dbName = "";
//some additional variables we need to display pages
//number of results displayed on a page. Change this if u want...
$limit = 12;
//format-strings for the page-links
//change it to ur needs (u may add some stylesheet-information), but be aware of the %d ´s.
//They will be replaced by some values later.
//Format for a page-link, if it links not to the current result-page
$page_array_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[%d]</a> ";
//Format for a page-link, if it links to the current result-page (here it is not a link)
$page_array_format_current_page = "%d ";
//Format for the next-link
$page_next_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[next]</a> ";
//Format for the back-link
$page_back_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[back]</a> ";
//DO NOT CHANGE THIS...
//offset point. Recordsets offset+limit are displayed
$offset = (!empty($_REQUEST['offset'])) ? (int)$_REQUEST['offset'] : 0;
/**
* Function getPagesArray()
* returns Pages-Array like this:
*
* Array {
* 1 => array {
* 'page' => 1,
* 'page_offset' => 0
* }
* 2 => array {
* 'page' => 2,
* 'page_offset' => 10
* }
* }
*
*
* @return array pages-array
*/
function getPageArray($hits, $range)
{
$pages = array();
$hits = (int)$hits;
$range = (int)$range;
//if there are more hits then range allows...
if($hits > $range) {
$page_number = $hits / $range;
$number_of_pages = ceil($page_number);
$offset = 0;
for($i=1; $i<= $number_of_pages; $i++) {
$pages[$i] = array('page' => $i, 'page_offset' => $offset);
$offset += $range;
}
}
return $pages;
}
function printPageArray($hits, $range)
{
global $page_array_format, $page_array_format_current_page, $page_back_format, $page_next_format, $offset, $limit;
$offset = (int)$offset;
$hits = (int)$hits;
$pages = getPageArray($hits, $range);
//var_dump($pages);
//get the back-link
if($offset > 0) {
//if that is not the first page
//show the back-link
$back_offset = $offset - $limit;
//should not be smaller then 0
$back_offset = ($back_offset < 0) ? 0 : $back_offset;
//print formated back-link
printf($page_back_format, $back_offset);
}
//get the page-links
for($i=1; $i <= sizeof($pages); $i++) {
if($pages[$i]['page_offset'] == $offset) {
//thats the number of current page
printf($page_array_format_current_page, $pages[$i]['page']);
} else {
//not the current page
printf($page_array_format, $pages[$i]['page_offset'], $pages[$i]['page']);
}
}
//get the next-link
if(($offset + $limit) < $hits) {
//if this is not the last page
$next_offset = $offset + $limit;
printf($page_next_format, $next_offset);
}
}
//do the connection
@MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
//choose the db
@mysql_select_db( "$dbName") or die( "Unable to select database");
//first we need a simple query to get the number of all records
$query = "SELECT * FROM $userstable WHERE NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%'";
$hits = @mysql_num_rows(mysql_query($query));
//Now the real query, but now with LIMIT-Clause
$query = "SELECT PRICE,RETAILPRICE,BUYURL,NAME,DESCRIPTION,IMAGEURL,IMPRESSIONURL FROM $userstable WHERE NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%'";
$query.= " LIMIT $offset, $limit";
$result = mysql_query($query) or die(mysql_error());
/* How many of these users are there? */
$number = @mysql_num_rows($result); //FIX!!!!!!
/* Print these results to the screen in a nice format */
$i = 0;
IF ($number == 0) :
//email if no items in the category
IF ($hits == 0):
PRINT "<font size=\"2\">New Product Coming Soon!</font><br>";
$adminEmail = "";
$subject = "The category called NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%' is no longer valid";
$body = "The category NAME LIKE '%Baitcast Reel%' AND ADVERTISERCATEGORY LIKE '%freshwater%' no longer has products in it. Page freshwater-spinnining-reels";
mail($adminEmail,$subject,$body,"FROM: $adminEmail");
ENDIF;
ELSEIF ($number > 0) :
PRINT "";
//Now its time to print out our pages-links
PRINT "<p align=center>";
//where ever u put next line, there will be displayed the page-array
printPageArray($hits, $limit);
PRINT "</p>";
PRINT "<table width=100% border=2 cellspacing=5 cellpadding=10>";
$x = 1;
echo "<tr>";
//start inside
WHILE ($i < $number):
$PRICE = mysql_result($result,$i,"PRICE");
$BUYURL = mysql_result($result,$i,"BUYURL");
$NAME = mysql_result($result,$i,"NAME");
$DESCRIPTION = mysql_result($result,$i,"DESCRIPTION");
$IMAGEURL = mysql_result($result,$i,"IMAGEURL");
$IMPRESSIONURL = mysql_result($result,$i,"IMPRESSIONURL");
//put td here
PRINT "<td align=center width=50% valign=top>";
PRINT "<strong><font color=\"#FF0000\" size=\"2\">\$$PRICE</font></strong><BR>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><img src=$IMAGEURL border=0 width=72><BR></A>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><strong><font size=\"2\">$NAME</a></strong></font><BR>";
PRINT "<font size=\"2\" padding=10>$DESCRIPTION</font><BR><BR>";
PRINT "<a href=$BUYURL target=blank rel=nofollow><strong><font size=\"2\">MORE...</a></strong></font><BR><BR>";
PRINT "<a href=$IMPRESSIONURL></A>";
//wrap it
//change where its 2,3,4 to 3,4,5 to display five in a row. - easy ha..
PRINT "</td>";
if ($x == 1 ) {$x ++;} else {
if ($x == 2 ) {echo "</tr><tr>"; $x=1;} else{$x ++;}
}
$i++;
ENDWHILE;
PRINT "</tr>";
echo "</table>";
//Now its time to print out our pages-links
PRINT "<p align=center>";
//where ever u put next line, there will be displayed the page-array
printPageArray($hits, $limit);
PRINT "</p>";
ENDIF;
//if is at end
?>