Extract data from paginated database entries and pass to a form in PHP
Stack Overflow won't allow me to post more than 2 hyperlinks and I need three, so to see my inquiry properly, please click on the link below:
http://bretleduc.com/inquiry.htm
Here is the original question that I posted to Stack Overflow:
http://stackoverflow.com/questions/15652430/extract-data-from-paginated-database-entries-and-pass-to-a-form
Here is the question...
This page I made:
Paginated Data
Shows questions/comments that people have entered in the following page:
Contact Artist
The theory is, once someone posts a comment or question in the Contact Artist page, the artist (Jackson David, whom I'm making this page for) can see the comment and respond to it in the Respond to a Question or Comment page. But right now, the artist has to copy and paste the Name and Email Address from the Paginated Data section to the Respond to a Question or Comment form.
What I'm trying to do is modify the Paginated Data page to include the ability to select an entry and have the Name and Email Address populate the Name and Email Address fields in another form. This way, the artist can answer the customer's queries easier by just clicking on the paginated entry (maybe using a radio button for example) and having the customer's Name and Email Address automatically populate into the following form:
Respond to a Question or Comment
Here is the code for the Paginated Data page which I got from a script site:
$lastPage) { // if it is greater than $lastpage
$pn = $lastPage; // force it to be $lastpage's value
}
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= ' ' . $pn . ' ';
$centerPages .= ' ' . $add1 . ' ';
} else if ($pn == $lastPage) {
$centerPages .= ' ' . $sub1 . ' ';
$centerPages .= ' ' . $pn . ' ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
$centerPages .= ' ' . $sub2 . ' ';
$centerPages .= ' ' . $sub1 . ' ';
$centerPages .= ' ' . $pn . ' ';
$centerPages .= ' ' . $add1 . ' ';
$centerPages .= ' ' . $add2 . ' ';
} else if ($pn > 1 && $pn < $lastPage) {
$centerPages .= ' ' . $sub1 . ' ';
$centerPages .= ' ' . $pn . ' ';
$centerPages .= ' ' . $add1 . ' ';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query("SELECT Comment_ID, Name, email, Comment FROM Comments ORDER BY Comment_ID DESC $limit");
//////////////////////////////// END Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
// This shows the user what page they are on, and the total number of pages
$paginationDisplay .= 'Page ' . $pn . ' of ' . $lastPage. ' ';
// If we are not on page 1 we can place the Back button
if ($pn != 1) {
$previous = $pn - 1;
$paginationDisplay .= ' Back ';
}
// Lay in the clickable numbers display here between the Back and Next links
$paginationDisplay .= '';
// If we are not on the very last page we can place the Next button
if ($pn != $lastPage) {
$nextPage = $pn + 1;
$paginationDisplay .= ' Next ';
}
}
///////////////////////////////////// END Adam's Pagination Display Setup ///////////////////////////////////////////////////////////////////////////
// Build the Output Section Here
$outputList = '';
while($row = mysql_fetch_array($sql2)){
$Comment_ID = $row["Comment_ID"];
$Name = $row["Name"];
$email = $row["email"];
$Comment = $row["Comment"];
$outputList .= '' . $Name . '
' . $email . '
' . $Comment . '
';
} // close while loop
?>
Adam's Pagination
Total Items:
I think I need to put some sort of form in the following line from the code:
$outputList .= '' . $Name . '
' . $email . '
' . $Comment . '
';
Further, it would be a bonus if we could make the selection of the entry automatically post the Name and Email Address to the Respond to a Question or Comment form without having to click a submit button.
If it would be easier to combine the code of Paginated Data and the code of Respond to a Question or Comment into one page, I can do that too.
Thanks all!