Jump to content


Photo

Catching a value from a form, then holding this value


  • Please log in to reply
No replies to this topic

#1 rewast

rewast
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 March 2006 - 07:46 PM

Hey there guys, I'm sure this is a simple one...but its been driving me crazy.

I've built a pagination script based on the various tutorials laying about. The script recieves a value from a form, which is then entered into a mysql query. Great I hear you say, and so did I!

However, when you click on the auto generated next/previous page links at the bottom, the script then gets the new page number from its own url...when it does this it no longer holds the value posted to it from the form!!! meaning the sql query returns no results defeating the whole pagination process!!!!!!!!

I've meddled with various if statements to keep the original posted value but to no avail. I've also contemplated using a session varible to hold the posted form data. I sure there must be a simple way of being able to hold the original form value though. I tried posting the form value to the url along with the page number, but it didnt work due to the lack of persistence of the original value.

Please if anyone can solve this problem I would be very grateful!!!

<?php
$sent = ($_REQUEST['genre']); //this is the value from my form
$num = 9; //this is a test value
$sent2 = ($_REQUEST['num']);
$column = 'genre_id';

$value = ($sent); //final value used by the query
echo "<table width=527 cellpadding=10> <tr> <td><img src=tsearch.jpg width=527 height=57></td> </tr><tr align=center><td>";


//header

require_once ('../mysql_connect.php');
//if there isnt a page number assign number 1

if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
//results per page
$max_results = 20;

$from = (($page * $max_results) - $max_results);

echo "<table width=500 cellpadding=0 cellspacing=0><tr>

<tr align=left> <td><h1>Title</h1></td> <td><h1>Artist</h1></td> <td><h1>Album</h1></td> <td><h1>Votes</h1></td> <td align=right><h1>Rating</h1></td></tr>";





$sql = mysql_query("SELECT track_name, track_id, album_name, artist_name, rating_total, no_of_rating
FROM trackcombo WHERE ($column) = '$value' ORDER BY rating_total desc LIMIT $from, $max_results");

while($row = mysql_fetch_array($sql)){
if ($bgcolor == "#E0DFE3"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0DFE3";
}
// loop out the results into a table with alternating row colours.

$track_id = $row[1];
$alb = $row[2];
$art = $row[3];
$rating_total = $row[4];
$no_of_rating = $row[5];
//catching the results from the db

echo "<tr bgcolor=$bgcolor><td align=left valign=middle><span class=track><a href=track.php?track_id=$track_id>$row[0]</a></span></td>
<td align=left><span class=subtitle>$art</span></td>
<td align=left><span class=subtitle>$alb</span></td>
<td align=left> <span class=subtitle>$no_of_rating</span></td>


<td align=right>";


"<table width=70>
<tr>
<td>";

if((($rating_total >= 0)or($rating_total == 0)) && ($rating_total <= 0.99)){
echo "<img src=0.jpg alt=$rating_total of 5 width=70 height=18>";
}
if((($rating_total >= 1.00)or($rating_total == 1.00)) && ($rating_total <= 1.99)){
echo "<img src=05.jpg alt=$rating_total of 5 width=68 height=14>";
}
if((($rating_total >= 2.00)or($rating_total == 2.00)) && ($rating_total <= 2.99)){
echo "<img src=1.jpg alt=$rating_total of 5 width=68 height=14>";
}
if((($rating_total >= 3.00)or($rating_total == 3.00)) && ($rating_total <= 3.99)){
echo "<img src=15.jpg alt=$rating_total of 5 width=68 height=14>";
}
if((($rating_total >= 4.00)or($rating_total == 4.00)) && ($rating_total <= 4.99)){
echo "<img src=2.jpg alt=$rating_total of 5 width=68 height=14>";
}

if((($rating_total >= 5.00)or($rating_total == 5.00)) && ($rating_total <= 5.99)){
echo "<img src=25.jpg alt=$rating_total of 5 width=68 height=14>";
}

if((($rating_total >= 6.00)or($rating_total == 6.00)) && ($rating_total <= 6.99)){
echo "<img src=3.jpg alt=$rating_total of 5 width=68 height=14>";
}

if((($rating_total >= 7.00)or($rating_total == 7.00)) && ($rating_total <= 7.99)){
echo "<img src=35.jpg alt=$rating_total of 5 width=68 height=14>";
}
if((($rating_total >= 8.00)or($rating_total == 8.00)) && ($rating_total <= 8.99)){
echo "<img src=4.jpg alt=$rating_total of 5 width=68 height=14>";
}
if((($rating_total >= 9.00)or($rating_total == 9.00)) && ($rating_total <= 9.99)){
echo "<img src=45.jpg alt=$rating_total of 5 width=68 height=14>";
}
if($rating_total == 10.0){
echo "<img src=5.jpg alt=$rating_total of 5 width=68 height=14>";
}
"
</td>
</tr>
</table>



";




}

// find out number of results
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM trackcombo WHERE ($column) = '$value'"),0);

//find out how many pages, round up
$total_pages = ceil($total_results / $max_results);

// Page number links
echo "<tr align=center><td colspan=5><h1>";
// back button

if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&num=$num\"> < </a> ";
}
//numbers of pages
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&num=$num\">$i</a> ";
}
}

// forward button
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&num=$num\"> > </a></h1>";
}
echo "</td></tr></table></td></tr></table>";


?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users