I'm just trying to finish off some code - hence my third post this evening!

Anyhow I have a script which is returning paged recordsets, the script uses 3 SQL queries:

1 - Gathers the results
2 - Limits the results gathered and displaying relevant to the page limit specified
3 - Finally displays the information

My problem is that at the moment my 2nd SQL query is not limiting the results and showing 1 result per page - instead all the results are shown on one page.

Originally when the SQL Query was hardcoded it looked like this:

$strSQL = mysql_query("SELECT * FROM job LIMIT $start,$pagelimit");

Since then I have incorporated some code to create the SQL on the fly, thus keeping the SQL in a variable $sql rather than it being hardcoded.

I have created the following code:

$limit_sql = "LIMIT ".$start.",".$pagelimit;
$applied_sql = $sql.$limit_sql;

If I print the code it looks like this:

SELECT jobid, date, title, description, location, skills, industry, contactid FROM job WHERE location = 'halifax' LIMIT 0,1

The code that finally runs the query is this:

$sql_result = mysql_query($applied_sql) or die('SQL Error - died at SQL Query2');

Any ideas why the code is failing to apply a limit to the results?

    maybe ure looping using query1 ? i cant say much till u post ure code

    reg
    kevin

      I can post all the code - but there are about 200 lines.

      If you PM your e-mail address, I'll happily mail it to you.

        SQL Query 1:

        $sql_result = mysql_query($sql) or die('SQL Error - died at SQLQuery1');

        $totalrows = mysql_num_rows($sql_result);

        SQL Query 2:

        $limit_sql = " LIMIT ".$start.",".$pagelimit;
        $applied_sql = $sql.$limit_sql;

        $sql_result = mysql_query($applied_sql) or die('SQL Error - died at SQL Query2');

        SQL Query 3:

        $sql_result = mysql_query($sql) or die('SQL Error - died at SQL Query3');
        $num_rows = mysql_num_rows($sql_result);

        if ($num_rows == 0){
        echo 'Sorry your search did not return any results. Please return to the search page <a href=search.php>here</a>';
        } else {

        while ($row = mysql_fetch_array($sql_result)){
        $jobid = $row["jobid"];
        $date= $row["date"];
        $title = $row["title"];
        $desc = $row["description"];
        $location = $row["location"];
        $salary = $row["salary"];
        $industry = $row["industry"];

          Is query2 in a loop?

          Where does $start and $pagelimit get set?

            No

            I solved it late last night night.

            SQL Query3 should read:

            $sql_result = mysql_query($applied_sql) or die('SQL Error - died at SQL Query3');
            $num_rows = mysql_num_rows($sql_result);

              Write a Reply...