MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 7th, 2002, 10:16 AM
DanC DanC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: New York
Posts: 2 DanC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MYSQL paging set and variables

Help!!
I have been playing around with Joe O'Donnell's Mysql Paging Class and everything works pretty much as advertised.

There is one problem though that I can't seem to solve.
When the query is hardcoded everything works just fine: the links take to all the right pages.

But when the query has a variable in it passed from a from (i.e. "Select * from table_name where CID=$cid") the script only ends up working for the first page. When you click on one of the page number links, the original variable from the form is lost and the script seems to run a new query and returns new results.

If anyone has any idea how to solve this, I would greatly appreciate it.

thanks, Dan

Reply With Quote
  #2  
Old August 7th, 2002, 06:00 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Dan,

What's the code you're using for the problem you're having?

It'll be helpful to determine the problem...
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old August 7th, 2002, 07:01 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
What version of php are you running?? and do you have register_globals on or off?

I think you maybe running a new version of php, thats why the limit isnt working

Reply With Quote
  #4  
Old August 8th, 2002, 11:15 AM
DanC DanC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: New York
Posts: 2 DanC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I was going to reply last night but fell asleep putting my 2 year old to bed. Oh, well!!

Anyway, I am running PHP 4.0.6 with Globals on (for now).

As for the code:

I am using the Recordset Paging Class by Joe O'Donnell, a form php file and a results file.

The Recordset Class (as I reconstructed it from the O'Donnell article) is:

<?php

class RecNav {

var $__linkId;
var $__dbType;
var $__query;
var $__template;
var $__templateHeader;
var $__templateFooter;
var $__recsPerPage;

function RecNav(&$LinkIdentifier, $Query, $Template=DEFAULT_TEMPLATE, $TemplateHeader=DEFAULT_TEMPLATE_HEADER, $TemplateFooter=DEFAULT_TEMPLATE_FOOTER, $RecsPerPage=DEFAULT_NUM_RECS) {


// Validate constructor parameters
if(!@mysql_query("SELECT 1", $LinkIdentifier))
{ die("MYSQL link identifier is invalid"); }
else
{
$this->__linkId = $LinkIdentifier;
}

if(!ereg("^SELECT", $Query))
{ die("Invalid query: query must start with 'SELECT'"); }
else
{ $this->__query = $Query; }

if($Template == "")
{ $this->__template = "<p><| row0 |></p><p><| row3 |></p>"; }
else
{ $this->__template = $Template; }

if($TemplateHeader == "")
{ $this->__templateHeader = DEFAULT_TEMPLATE_HEADER; }
else
{ $this->__templateHeader = $TemplateHeader; }

if($TemplateFooter == "")
{ $this->__templateFooter = DEFAULT_TEMPLATE_FOOTER; }
else
{ $this->__templateFooter = $TemplateFooter; }


if(!is_numeric($RecsPerPage) || $RecsPerPage < 1)
{ $this->__recsPerPage = DEFAULT_NUM_RECS; }
else
{ $this->__recsPerPage = $RecsPerPage; }
}

function ShowRecs($Page=1) {
$finalOutput = $this->__templateHeader;


if($Page <= 1)
{
$Page = 1;
$query = $this->__query . " LIMIT 0, " . $this->__recsPerPage;
}
else
{
$query = $this->__query . " LIMIT " . (($Page-1) * $this->__recsPerPage) . ", " . $this->__recsPerPage;
}

$result = mysql_query($query);
$hasRecords = mysql_num_rows($result) == 0 ? false : true;

if($hasRecords)
{
// At least one records returned from the query
while($row = mysql_fetch_row($result))
{
$newRow = $this->__template;

for($i = 0; $i < mysql_num_fields($result); $i++)
{ $newRow = str_replace("<| row" . $i . " |>", $row[$i], $newRow); }

$finalOutput .= $newRow;
}
}

else
{
// No records returned from the query
$newRow = $this->__template;
$newRow = str_replace("<| row0 |>", "No records found", $newRow);

// Replace all template tags with &nbsp;
$newRow = ereg_replace("<\| row[0-9] \|>", "&nbsp;", $newRow);

$finalOutput .= $newRow;
}

$finalOutput .= $this->__templateFooter;

// Build the recordset paging links
$numTotalRecs = mysql_num_rows(mysql_query($this->__query));
$numPages = ceil($numTotalRecs / $this->__recsPerPage);
$nav = "";


// Can we have a link to the previous page?
if($Page > 1)
$nav .= "<a href='$PHP_SELF?page=" . ($Page-1) . "'><< Prev</a> |";

for($i = 1; $i < $numPages+1; $i++)
{
if($Page == $i)
{
// Bold the page and dont make it a link
$nav .= " <b>$i</b> |";
}
else
{
// Link the page
$nav .= " <a href='$PHP_SELF?page=$i'>$i</a> |";
}
}

// Can we have a link to the next page?
if($Page < $numPages)
$nav .= " <a href='$PHP_SELF?page=" . ($Page+1) . "'>Next >></a>";

// Strip the trailing pipe if there is one
$nav = ereg_replace("\|$", "", $nav);

$finalOutput .= "<div align='right'><font face='verdana' size='1'><br>Pages: $nav</font></div>";

return $finalOutput;

}

}

?>


The form file is simply a test file with one drop down field:

<html>
<head>
<title>Paged Results Demo</title>
</head>
<body>


<form method="POST" name="search" action="paging.php">

<Select name="origin">
<Option value="Please Select">Please Select</option>
<Option value="German">German</option>
<Option value="Czech">Czech</option>
<Option value="Italian">Italian</option>
</select>
<input type="submit" value="Start Search" name="Search">
<input type="reset" name="Reset" value="Reset">
</form>
</body>
</html>


and the results display file:

<html>
<head>
<title> Recordset Paging Example </title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" name="test" action="">
<input type="hidden" name="origin" value="<?php echo $origin?>"></form>
<?php

require("class.recnav.php");

$s = mysql_connect("localhost", "xxx", "xxxxxx");
$d = mysql_select_db("dbname", $s);
$r = new RecNav($s, "SELECT * FROM table_name where Bass_Origin='$origin'", $bodyTemplate, $headerTemplate, "", 1);

echo $r->ShowRecs($page);

?>

</body>
</html>

Set up like this, this works fine for the first page, but as soon as you click on one of the page number or next links, the $origin variable gets lost and a different query ends up being run (with a different result).

If I hard code the Bass_Origin (Bass_Origin='German', for example), than everything works fine for all the page number links.

Not to confuse matters, but I started playing around with PHP sessions. In one way, this helps immediately. If I put in :
<?php
session_start();
session_register("origin");
?>

then the variable sticks and gets passed on to all the page links. Everything is fine and great except that then I can't seem to change the value of the variable once it's set this way.

I'll stop here for now before I confuse things farther. Thanks so much for your input.
Dan

Reply With Quote
  #5  
Old August 9th, 2002, 11:26 AM
Phynias Phynias is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 18 Phynias User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
put this at the top of your display page
$origin = $_POST['origin'];


With php 4.2 register globals are turned off for security reasons
so you must use $_GET $_POST $_SESSION $_COOKIE or even just $_REQUEST

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MYSQL paging set and variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway