help retrieiving results and doing pagination


Posted on 16th Feb 2014 07:03 pm by admin

Having some trouble trying to get the results to show on more than just one page.

What is happening is that when i input a subject or zip code, i get results and links on the bottom to show the number of pages, but when i click on them it gives me a broken link error

Here is the code that i have at the top of my html code before the <html> tag begins

Code: if(!isset($_GET['resultsPage'])){
$resultsPage = 1;
} else {
$resultsPage = $_GET['resultsPage'];
}
// Define the number of results per page
$max_results = 9;

// Figure out the limit for the query based
$from = (($resultsPage * $max_results) - $max_results);

that is whats supposed to get the pages, and the number of search results

here is t he code i have inside my <body> tag that echoes the results and builds the links for the pages

Code: // perform the search
$subject = $_POST['subject'];
$location = $_POST['location'];

$sql = "SELECT * FROM tutorProfiles WHERE MATCH(subject, location) AGAINST('$subject*' '$location*' IN BOOLEAN MODE) LIMIT $from, $max_results";
$result = mysql_query($sql) or die("Problem, with Query:".mysql_error());

// Get number of articles, assign value to a variable
$count = mysql_num_rows($result);

echo "<h3>Search Results</h3>";
echo "<p class='resultspara'>There is a total of $count results found on our database.</p>";

$TableRows = mysql_num_rows($result);
$i = 0;

while ($i <$TableRows)

{
//Add resulting tablerow to relvant variable
$tutorId = mysql_result($result, $i, "id");
$first = mysql_result($result, $i, "first");
$school = mysql_result($result, $i, "school");
$degree = mysql_result($result, $i, "degree");
$class = mysql_result($result, $i, "class");

echo"
<div id='profileBox'>
<div id='badgeImg'>
<img src='images/imgBG.png' name='imgBadge' width='76' height='70' align='left' id='imgBadge' />
<h2>$first</h2>
<p>$school<br />
$degree - $class
</p>
</div>
<div id='profleBtn'>
<a href='profile.php?id=$tutorId'><img src='images/linkBtn.png' alt='view Profile' width='150' height='30' border='0' /></a>
</div>
</div>";
// loop through all results and indent number on each loop
$i ++;

} // close while loop

//Beggin Pagination

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tutorProfiles"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_newspage = ceil($total_results / $max_results);

echo "<p style="clear:both;" align="center">n";


// Build Previous Link
if($resultsPage > 1)
{
$prev = ($resultsPage - 1);
echo "<a href="results.php.php?resultsPage=$prev">Previous</a>n ";
}

for($p = 1; $p <= $total_newspage; $p++)
{
if(($resultsPage) == $p)
{
echo "$pn ";
} else {
echo "<a href="result.php?resultsPage=$i">$p</a>n ";
}
}

// Build Next Link
if($resultsPage < $total_newspage)
{
$next = ($resultsPage + 1);
echo "<a href="results.php?resultsPage=$next">Next</a>n";
}
echo "</p>n";
//End pagination Script

Anyway if someone could take a look at the code when i would gladly appreciate it

Thanks in advance

No comments posted yet

Your Answer:

Login to answer
125 Like 50 Dislike
Previous forums Next forums
Other forums

Quick Question about echo value
Hey guys, I'm trying to get something to show differently in one of my scripts. I'm trying to make

xml element exists
Code: [Select]<?xml version="1.0"?>
<Addresses>
<

Calculating a rating by adding number of points and dividing by number of items
I have a site that users can post links to files to download. They can rate these files on a 1-5 sca

Java API in PHP?
I have an application that we use internally here at the office.

The software company provide

Storing the referrer in session... problems with tabs
Hello All

I am currently working on an ERP project based on the MVC methodology, when a user

Anti Spam Code
Ok where do i start? Probably by telling you I have very little working knowledge of PHP and that I

How can I get my program to read a larger array ??
Hi:

I have this program that reads from an array to do calculations. The array are just t

Writing Windows Device Drivers with C
Yes: one of the nice features of C is void*. You can put anything there and get anything out. Very

How can I Compare two xml documents?
Hi all,

I am doing a POC for my project and I am using XE database 10g version.

finding key position of specified value in multi-dimensional array
Code: $openedfile = fopen($tfc_file4, "r");
$rc = 1;
while(!feof($openedfile))
{<

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash