[SOLVED] ULTIMATE PAGINATION CHALLENGE

Looking to hire a PHP developer for a paid position? Looking for a paid PHP job? Want to post your resume? Let the job hunt begin...

Moderator: General Moderators

Post Reply
cmarti
Forum Newbie
Posts: 4
Joined: Thu Aug 05, 2004 11:25 pm

ULTIMATE PAGINATION CHALLENGE

Post by cmarti »

I've got a challenge for everyone. The are a lot of pagination scripts out there, but none that do what I am looking for. I've got a MySQL database with two tables (User_Info and GradeBook). User_Info includes StuID and Password. GradeBook includes StuId, Assignment, and Grade. Each student has multiple grades. I'm willing to pay $20 dollars (sorry, that's all I have), to anyone who can help.

On one page (body) I have a form:

Code: Select all

<form action="StuGetIn.php" method="POST">
Student ID: <input type="text" name="StuUserID" size="14">
Password: <input type="password" name="StudPassword" size="14">
<input type="image" src="../Images/Go.gif"></form>
The query for the StuGetIn.php page that I would like to use is:

Code: Select all

$username = $_POST&#1111;"StuUserID"];
$password = $_POST&#1111;"StudPassword"];
select * from User_Info, GradeBook 
where User_Info.stuID=GradeBook.stuID 
AND User_Info.StuID='$username'and User_Info.Password='$password' 
ORDER BY DatePosted DESC, ClassName DESC
With that said, I would like a simple working pagination (previous/next) script that checks the values from the form against the database and displays 5 results per page.

Please help.
-Casey
casey@martincreations.com
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

congratulations! you get your thread MOVED! Have a nice day!
cmarti
Forum Newbie
Posts: 4
Joined: Thu Aug 05, 2004 11:25 pm

Thread Moved Where?

Post by cmarti »

Thread Moved Where?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's now in the Job Hunt forum, you posted it in the PHP - Code forum, which is the wrong place.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

session_start();

// clean up posted data
if (isset($_POST["StuUserID"])) {
 $_SESSION['username'] = mysql_escape_string($_POST["StuUserID"]);
}
if (isset($_POST["StudPassword"]) {
 $_SESSION['password'] = mysql_escape_string($_POST["StudPassword"]);
}

// retrieve data
if (!isset($_SESSION['username']) || (!isset($_SESSION['password']))
{
  // redirect to input page - we need username and password
  header('Location: http://submitpageurl');
  exit(0);
}
else
{
  $username = $_SESSION['username'];
  $password = $_SESSION['password'];
}
// get the requested page number
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} 

// count the available rows
$query = 'SELECT COUNT(*) FROM User_Info, GradeBook  WHERE ';
$query .= 'User_Info.stuID=GradeBook.stuID AND ';
$query .= "User_Info.StuID='$username'and ";
$query .= "User_Info.Password='$password'";  
$result = mysql_query($query);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

// find the number of the last page
$rows_per_page = 15;
$lastpage  = ceil($numrows/$rows_per_page);

// make sure pageno is in range
$pageno = (int)$pageno;
if ($pageno < 1) {
   $pageno = 1;
} elseif ($pageno > $lastpage) {
   $pageno = $lastpage;
}

// build query
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = 'SELECT * FROM User_Info, GradeBook  WHERE ';
$query .= 'User_Info.stuID=GradeBook.stuID AND ';
$query .= "User_Info.StuID='$username'and ";
$query .= "User_Info.Password='$password' ";
$query .= 'ORDER BY DatePosted DESC, ClassName DESC ';
$query .= $limit;
$result = mysql_query($query);

// process stuff returned by query - 
while ($row = mysql_fetch_assoc($result))
{
  print_r($row);
}

// build pagination stuff
if ($pageno == 1) {
   echo " FIRST PREV ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}

echo " ( Page $pageno of $lastpage ) ";

if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
Last edited by timvw on Sat Aug 07, 2004 1:59 am, edited 1 time in total.
cmarti
Forum Newbie
Posts: 4
Joined: Thu Aug 05, 2004 11:25 pm

problem solved

Post by cmarti »

Thanks timvw, but I got some help from someone else. I was hoping people would email me to find out if I still needed some help. I hope I didn't put you out. For any inconviences, if you have a site that you would like me to advertise on mine, I'll be happy to do so.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: problem solved

Post by JayBird »

cmarti wrote:Thanks timvw, but I got some help from someone else. I was hoping people would email me to find out if I still needed some help. I hope I didn't put you out. For any inconviences, if you have a site that you would like me to advertise on mine, I'll be happy to do so.
Very convenient.

If you asked for help, it would have been courtesy to come back and post that your problem had been solved before someone wasted time providing code.

Mark
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: problem solved

Post by hawleyjr »

cmarti wrote:Thanks timvw, but I got some help from someone else. I was hoping people would email me to find out if I still needed some help. I hope I didn't put you out. For any inconviences, if you have a site that you would like me to advertise on mine, I'll be happy to do so.
What a joke...
cmarti
Forum Newbie
Posts: 4
Joined: Thu Aug 05, 2004 11:25 pm

I'm sorry

Post by cmarti »

I'm sorry, I really am... I posted it before I went to bed and didn't think someone would do it so quickly. I should have been more clear that I would like to be contacted first. However, I did NOT use the code above and I offered to put a link, description, and praise on a site that will have heavy traffic.

It was my fault however I suggest not putting code up so everyone can see when someone is offering to pay for it.

Greatest appologies timvw.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I don't care about the money...

But i do care about my lazyness....... and the copy-paste was quite intensive :P
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

timvw if you ever make it to Florida USA I'll buy you a beer.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Innocence or trickery?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hahah.. that's so wrong. :P
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

The code he posted would throw you an error anyhows:

Code: Select all

if (!isset($_SESSION['username']) || (!isset($_SESSION['password))
edit: this line too! :D

Code: Select all

if (isset($_POST["StudPassword"]) {
:P
Last edited by d3ad1ysp0rk on Sat Aug 07, 2004 2:28 am, edited 1 time in total.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Code: Select all

if(($_SESSION['username'] == "") || ($_SESSION['password'] == ""))
Someone forgot the ending '] ;)
Image Image
Post Reply