Page 1 of 1

ULTIMATE PAGINATION CHALLENGE

Posted: Thu Aug 05, 2004 11:25 pm
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

Posted: Thu Aug 05, 2004 11:29 pm
by feyd
congratulations! you get your thread MOVED! Have a nice day!

Thread Moved Where?

Posted: Thu Aug 05, 2004 11:38 pm
by cmarti
Thread Moved Where?

Posted: Thu Aug 05, 2004 11:41 pm
by feyd
It's now in the Job Hunt forum, you posted it in the PHP - Code forum, which is the wrong place.

Posted: Fri Aug 06, 2004 12:41 am
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> ";
}

problem solved

Posted: Fri Aug 06, 2004 7:02 am
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.

Re: problem solved

Posted: Fri Aug 06, 2004 9:09 am
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

Re: problem solved

Posted: Fri Aug 06, 2004 9:13 am
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...

I'm sorry

Posted: Fri Aug 06, 2004 2:04 pm
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.

Posted: Fri Aug 06, 2004 2:57 pm
by timvw
I don't care about the money...

But i do care about my lazyness....... and the copy-paste was quite intensive :P

Posted: Fri Aug 06, 2004 2:58 pm
by hawleyjr
timvw if you ever make it to Florida USA I'll buy you a beer.

Posted: Fri Aug 06, 2004 3:38 pm
by nigma
Innocence or trickery?

Posted: Fri Aug 06, 2004 3:39 pm
by feyd
hahah.. that's so wrong. :P

Posted: Sat Aug 07, 2004 12:45 am
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

Posted: Sat Aug 07, 2004 1:06 am
by phice

Code: Select all

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