Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Sorting in MySQL query get options

 

 


nmsinc
User

Jan 28, 2012, 1:53 PM

Post #1 of 3 (173 views)
Shortcut
Sorting in MySQL query get options Can't Post

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 ?>


Jason
Staff / Moderator


Jan 30, 2012, 10:15 AM

Post #2 of 3 (161 views)
Shortcut
Re: [nmsinc] Sorting in MySQL query get options [In reply to] Can't Post

Hi,

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


Code
<?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 - Programmer 
interactivetools.com

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


nmsinc
User

Jan 30, 2012, 10:54 AM

Post #3 of 3 (160 views)
Shortcut
Re: [Jason] Sorting in MySQL query get options [In reply to] Can't Post

Thanks Jason, worked great!