yandoo Posted May 21, 2007 Share Posted May 21, 2007 Hi there, I was hoping for some expert help & guidance on my current php problem please!! Basically i have gona through the pagination tutorial (very helpful) and am now integrating the pagination with a recordset i have already created. I get the records to display results accordingly and also at the bottom of the page is the "NEXT 6" and "PREVIOUS 6" link (I limited the records to display 6 only per page). They are only diaplyed as text though NOT as a hyperlink! I think im very close to getting this to work correctly but am currently racking my brain and pulling out my hair here. If anybody can help id be soooo gr8ful. Please see attachments for a screen print of my page and below is the code uysed to create it: <?php $limit = 6; $query_count = "SELECT count(*) FROM teachersname"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM teachersname WHERE " . $_POST['field'] . " LIKE '%$find%' LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } ?> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } --> </style></head> <body> <span class="border_bottom"> <?php //check if the user entered data in the form if (isset($_POST['find'])) { //data has been entered so lets search the mofo echo "<h2>Results</h2><p>"; //sanitise the data $find = strtoupper($_POST['find']); $find = strip_tags($_POST['find']); $find = trim ($_POST['find']); //connect to the db //mysql_connect("localhost", "root", "winn3rs") or die(mysql_error()); //mysql_select_db("laptop_loan_database") or die(mysql_error()); //Now we search for our search term, in the field the user specified //$query = "SELECT * FROM teachersname WHERE " . $_POST['field'] . " LIKE '%$find%'" ; $data = mysql_query($query); //And we display the results while($result = mysql_fetch_array( $data )) { echo"<table width=\"200\" border=\"0\" class=\"border_bottom\"> \n"; echo "<tr> \n"; echo "<td> </td> \n"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td>"; echo "<strong>Client Name</strong>"; echo "</td>"; echo "<td width=\"75\" style =\"text-align: left\""; ?> <a href="search_client_details.php?recordID=<?php echo $result['Client']; ?>"><?php echo $result['Client']; ?> [/url] <?php echo " </td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td>"; echo "<strong>Department Code</strong>"; echo "</td>"; echo "<td>"; echo ""; echo $result['DepartmentCode']; echo ""; echo "</td>"; echo "</tr> \n"; echo "<tr> \n"; echo "<td> </td> \n"; echo "</td> \n"; echo "</tr> \n"; echo "</table> \n"; echo" "; } if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."[/url] "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i[/url] "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i[/url] "); echo " "; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."[/url]"); }else{ echo("NEXT".$limit); echo "\n"; } ?> </span> <?php } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query"; } ?> <?php mysql_free_result($user_conditional); ?> Please help me here, i feel i'm close but am quite stuck at the minute and any help would be brilliant!!!! Many Thanks Tom [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/52337-pagination-help/ Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 please use code tags and what appears as text not hyperlinks ? Quote Link to comment https://forums.phpfreaks.com/topic/52337-pagination-help/#findComment-258249 Share on other sites More sharing options...
yandoo Posted May 21, 2007 Author Share Posted May 21, 2007 Hi, The "NEXT 6" and the "PREVIOUS 6" are only text NOT hyperlinked as they should be. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/52337-pagination-help/#findComment-258268 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 can you post it in code tags please.. as you code is altered by the form.. PREVIOUS will only be a link on pages greater than 1 Quote Link to comment https://forums.phpfreaks.com/topic/52337-pagination-help/#findComment-258272 Share on other sites More sharing options...
yandoo Posted May 21, 2007 Author Share Posted May 21, 2007 Hi, Thanks for reply!! Perhaps there is more than one problem then because in between the "NEXT" & "PREVIOUS" is the number 1 (as text)....perhaps this bit of code is not functioning properly??? The main problem is the hyper-link though.... Here is the code in tag...... <?php $limit = 6; $query_count = "SELECT count(*) FROM teachersname"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM teachersname WHERE " . $_POST['field'] . " LIKE '%$find%' LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } ?> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } --> </style></head> <body> <span class="border_bottom"> <?php //check if the user entered data in the form if (isset($_POST['find'])) { //data has been entered so lets search the mofo echo "<h2>Results</h2><p>"; //sanitise the data $find = strtoupper($_POST['find']); $find = strip_tags($_POST['find']); $find = trim ($_POST['find']); //connect to the db //mysql_connect("localhost", "root", "winn3rs") or die(mysql_error()); //mysql_select_db("laptop_loan_database") or die(mysql_error()); //Now we search for our search term, in the field the user specified //$query = "SELECT * FROM teachersname WHERE " . $_POST['field'] . " LIKE '%$find%'" ; $data = mysql_query($query); //And we display the results while($result = mysql_fetch_array( $data )) { echo"<table width=\"200\" border=\"0\" class=\"border_bottom\"> \n"; echo "<tr> \n"; echo "<td> </td> \n"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td>"; echo "<strong>Client Name</strong>"; echo "</td>"; echo "<td width=\"75\" style =\"text-align: left\""; ?> <a href="search_client_details.php?recordID=<?php echo $result['Client']; ?>"><?php echo $result['Client']; ?> [/url] <?php echo " </td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td>"; echo "<strong>Department Code</strong>"; echo "</td>"; echo "<td>"; echo ""; echo $result['DepartmentCode']; echo ""; echo "</td>"; echo "</tr> \n"; echo "<tr> \n"; echo "<td> </td> \n"; echo "</td> \n"; echo "</tr> \n"; echo "</table> \n"; echo" "; } if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."[/url] "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i[/url] "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i[/url] "); echo " "; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."[/url]"); }else{ echo("NEXT".$limit); echo "\n"; } ?> </span> <?php } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query"; } ?> <?php mysql_free_result($user_conditional); ?> Thank You Tom Quote Link to comment https://forums.phpfreaks.com/topic/52337-pagination-help/#findComment-258464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.