MIN - MAX DB Query

  • Michael
  • Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #125297 by Michael
MIN - MAX DB Query was created by Michael
Hi Guys,

Im needing to query DB for minimum and maximum membership_id in DB??
Needs to display like this Eg: Membership Draw Numbers 1000 - 3363



Ideas?
Thank you
Attachments:

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #125298 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic MIN - MAX DB Query
Hi

You can try to use the code below(PHP code)

$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('MAX(membership_id) AS max_membership_id')
->select('MIN(membership_id) AS min_membership_id')
->from('#__osmembership_subscribers');
$db->setQuery($query);
$row = $db->loadObject();

echo $row->max_membership_id;
echo $row->min_membership_id;


If it's SQL, just use SELECT MAX(membership_id), MIN(membership_id) FROM #__osmembership_subscribers

(#__osmembership_subscribers needs to be replaced with correct table name, depends on database prefix on your site)

Tuan

Please Log in or Create an account to join the conversation.

  • Michael
  • Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago - 4 years 10 months ago #125299 by Michael
Replied by Michael on topic MIN - MAX DB Query
Thanks so much Tuan... Worked perfectly ... Michael
Last edit: 4 years 10 months ago by Michael.

Please Log in or Create an account to join the conversation.

  • Michael
  • Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #125320 by Michael
Replied by Michael on topic MIN - MAX DB Query
Hi Tuan,
I have a slightly tricker one this time.
Is it possible to create a button that exports a .xlsx spreadsheet of all member numbers between min and max that are not used??
Kind regards,
Michael

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #125325 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic MIN - MAX DB Query
Hi Michael

It's unfortunately, this is not something we can guide you. For this, you will have to hire a developer to write code to develop that feature for you. It's not something quick and easy which we can guide you

Tuan

Please Log in or Create an account to join the conversation.