Sorting in MySQL query get options

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 30, 2012   (RSS)

By nmsinc - January 28, 2012

I'm using the following in a Get Options MySQL query. I need to SORT by "member_company_name" and not by the the file number. Any help would be appreciated!

Thanks - nmsinc

<?php if ($CURRENT_USER['isAdmin']):?>
<?php
$where = "";
$where = "WHERE member_type = 'Insurance'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>

<?php elseif (!$CURRENT_USER['isAdmin'] AND $CURRENT_USER['company_type'] == "Independent"): ?>
<?php
$where = "";
$where = "WHERE member_type = 'Insurance'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>

<?php else: ?>
<?php
$where = "";
$where = "WHERE num = '".$CURRENT_USER['member_company_accounts']."'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>

<?php endif ?>
nmsinc

Re: [nmsinc] Sorting in MySQL query get options

By Jason - January 30, 2012

Hi,

You need to add ORDER BY member_company_name to the end of your query like this:

<?php if ($CURRENT_USER['isAdmin']):?>

<?php
$where = "";
$where = "WHERE member_type = 'Insurance'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>
ORDER BY member_company_name

<?php elseif (!$CURRENT_USER['isAdmin'] AND $CURRENT_USER['company_type'] == "Independent"): ?>

<?php
$where = "";
$where = "WHERE member_type = 'Insurance'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>
ORDER BY member_company_name

<?php else: ?>

<?php
$where = "";
$where = "WHERE num = '".$CURRENT_USER['member_company_accounts']."'";
?>
SELECT num, member_company_name
FROM `<?php echo $TABLE_PREFIX ?>member_companies`
<?php echo $where; ?>
ORDER BY member_company_name

<?php endif ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/