Jump to content

COUNT, INNER JOIN and LIMIT?


Kristoff1875
Go to solution Solved by Barand,

Recommended Posts

Hi, could anyone tell me why this isn't working?

SELECT o.*, p.*, COUNT(*) as num
	FROM Offers o
	INNER JOIN Partners p USING (PartnerID) LIMIT $start, $limit

The LIMIT is to make pagination, it's working when just calling info from one table, but when I INNER JOIN the tables, the second page is just displaying blank.

 

Any help appreciated. Thanks

Link to comment
Share on other sites

Yep, would that be the problem?

$query = "SELECT o.*, p.*, COUNT(*) as num
FROM Offers o
INNER JOIN Partners p USING (PartnerID)";

$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = "searchoffers.php"; //your file name  (the name of this file)
$limit = 5; //how many items to show per page
$page = $_GET['page'];
if($page) 
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT o.*, p.*, COUNT(*) as num
FROM Offers o
INNER JOIN Partners p USING (PartnerID) WHERE PartnerArea = '$offerarea' LIMIT $start, $limit";
Edited by Kristoff1875
Link to comment
Share on other sites

Ok, have changed some things that I thought may be the problem... But still no joy:

$query = "SELECT o.*, p.*, COUNT(*) as num
	FROM Offers o
	INNER JOIN Partners p USING (PartnerID)
	WHERE PartnerArea = '$offerarea'";
	
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
	
	/* Setup vars for query. */
	$targetpage = "searchoffers.php";			//your file name  (the name of this file)
	$limit = 1; 								//how many items to show per page
	$page = $_GET['page'];
	if($page) 
		$start = ($page - 1) * $limit; 			//first item to display on this page
	else
		$start = 0;								//if no page var is given, set start to 0
	
	/* Get data. */
	$sql = "SELECT o.*, p.*
	FROM Offers o
	INNER JOIN Partners p USING (PartnerID) WHERE PartnerArea = '$offerarea' LIMIT $start, $limit";
	$result = mysql_query($sql);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.