Jump to content

Recommended Posts

Hi,

 

i need help, i have a page that should display all the list of benefits.

whats happening with my current code is that it only displays the latest benefit item.

how can i fix this?

this is the site

http://www.mumcentre.com.my/index.php?option=com_classifieds&act=benefits

try to click the "click here to see the complete list of benefits...." let say for bebehaus.

 

notice at the bottom part that there are 2 benfits for this one.

hope you could help me fix my query in such a way that i will display all the benefits from the listing page

below is my current query

$database->setQuery(" SELECT (benefits.`provider`) $query ORDER BY benefits.`id` DESC LIMIT $pageNav->limitstart, $pageNav->limit ");
$providers	= $database->loadObjectList();
foreach ($providers as $provider) {
	$query = "SELECT providers.name AS `providername`, benefits.* "
	. " FROM `#__classifieds_providers_benefits` benefits "
	. " LEFT JOIN `#__classifieds_providers` providers "
	. " ON benefits.provider = providers.id "
	. " WHERE `provider` = " . $provider->provider 
	. " AND benefits.`published` = 1"
	. " ORDER BY `dateadded` DESC "
	. " LIMIT 0,1";
	$database->setQuery($query);
	if (!$benefit = $database->query()) { echo $database->stderr(); return; }
	$benefit	= $database->loadObjectList();
	if($benefit)
	$benefits[] = $benefit[0];

 

hope you could help me with this.

 

thanks so much!

Link to comment
https://forums.phpfreaks.com/topic/54545-help-on-my-mysql-query/
Share on other sites

sorry, this is the current code

	$database->setQuery(" SELECT DISTINCT(benefits.`provider`) $query ORDER BY benefits.`id` DESC LIMIT $pageNav->limitstart, $pageNav->limit ");
$providers	= $database->loadObjectList();
foreach ($providers as $provider) {
	$query = "SELECT providers.name AS `providername`, benefits.* "
	. " FROM `#__classifieds_providers_benefits` benefits "
	. " LEFT JOIN `#__classifieds_providers` providers "
	. " ON benefits.provider = providers.id "
	. " WHERE `provider` = " . $provider->provider 
	. " AND benefits.`published` = 1"
	. " ORDER BY `dateadded` DESC "
	. " LIMIT 0,1";
	$database->setQuery($query);
	if (!$benefit = $database->query()) { echo $database->stderr(); return; }
	$benefit	= $database->loadObjectList();
	if($benefit)
	$benefits[] = $benefit[0];

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.