Search code examples
mysqllimitinner-join

INNER JOIN doesn't work when LIMIT is added


here is the code I'm working with and works perfectly fine:

$curEvent_query = @mysql_query("SELECT ppl.Fname, ppl.Lname, ppl.Email, plans.ID, plans.Date FROM ppl INNER JOIN plans ON plans.ID IN ($List) AND plans.OwnerID=ppl.ID AND plans.Date >= CURDATE() ORDER BY plans.Date ASC");

But once I add the LIMIT, the code nolonger works:

$curEvent_query = @mysql_query("SELECT ppl.Fname, ppl.Lname, ppl.Email, plans.ID, plans.Date FROM ppl INNER JOIN plans ON plans.ID IN ($List) AND plans.OwnerID=ppl.ID AND plans.Date >= CURDATE() ORDER BY plans.Date ASC LIMIT $offset, $rowsPerPage");

The reason for adding LIMIT is because I want to do paging. Any ideas what I'm doing wrong?


Solution

  • Please add the output of:

    $query = "SELECT ppl.Fname, ppl.Lname, ppl.Email, plans.ID, plans.Date FROM ppl INNER JOIN plans ON plans.ID IN ($List) AND plans.OwnerID=ppl.ID AND plans.Date >= CURDATE() ORDER BY plans.Date ASC LIMIT $offset, $rowsPerPage";
    echo $query;
    $curEvent_query = mysql_query($query);
    if (!$curEvent_query)
        echo mysql_error();