Sort order by variable?

Hi all,
Am wondering how to sort my results on a page by a variable.
My sql code now is this:
mysql_select_db($database_broker, $broker);
$query_brokers = "SELECT * FROM brokers";
$query_limit_brokers = sprintf("%s LIMIT %d, %d",
$query_brokers, $startRow_brokers, $maxRows_brokers);
$brokers = mysql_query($query_limit_brokers, $broker) or
die(mysql_error());
$row_brokers = mysql_fetch_assoc($brokers);
The variable I have written looks like this :
$valrate1 =
(($row_brokers['broker_rating']/$row_brokers['broker_num_votes'])+
($row_brokers['broker_rating_two']/$row_brokers['broker_num_votes_two'])+
($row_brokers['broker_rating_three']/$row_brokers['broker_num_votes_three']))/3;
basically, i want to add an ORDER BY $valrate1 to the sql
query, have tried a few different things with no luck. Am not sure
where the variable code should go , any ideas would be great.
xtian

Hi all,
Am wondering how to sort my results on a page by a variable.
My sql code now is this:
mysql_select_db($database_broker, $broker);
$query_brokers = "SELECT * FROM brokers";
$query_limit_brokers = sprintf("%s LIMIT %d, %d",
$query_brokers, $startRow_brokers, $maxRows_brokers);
$brokers = mysql_query($query_limit_brokers, $broker) or
die(mysql_error());
$row_brokers = mysql_fetch_assoc($brokers);
The variable I have written looks like this :
$valrate1 =
(($row_brokers['broker_rating']/$row_brokers['broker_num_votes'])+
($row_brokers['broker_rating_two']/$row_brokers['broker_num_votes_two'])+
($row_brokers['broker_rating_three']/$row_brokers['broker_num_votes_three']))/3;
basically, i want to add an ORDER BY $valrate1 to the sql
query, have tried a few different things with no luck. Am not sure
where the variable code should go , any ideas would be great.
xtian

Similar Messages

  • Change Sorting order in F4 Help in BEx Query

    Hello All,
    My users want to change the sorting order of variable (e.g. Calmonth) in the selection screen (while executing a query).
    Currently, by default,the sorting order is ascending on key.
    I need to change it to descending on key.
    How to change the sorting order for F4 ONLY?
    Thanks,
    Mainak

    Hi,
    You can sort the Char.Values by doing settings in Query Designer :
    Say for 0calmonth :
    In its Display properties tab,You select appropriate options in
    Sort Char -> select the name
    sort by -> Key/Text
    Sort Direction -> Ascending/Descending.
    You will then have them in required order.
    ALso if you want it only for F4 help:
    In F4 help screen,you will see two arrow buttons next to Char. name. they are useful for sorting the values to either descending or ascending.
    Hope it helps:)
    Edited by: Sriman on Nov 12, 2008 5:17 PM

  • Sorting in the variable screen

    Hello,
    I use BW 7.0 and have a problem with the variable screen.
    In the web-report I have three queries with different and same variables. I know that I can adjust the sorting of variables in the query designer. But this has no affect to the sorting of the variable screen.
    Does anybody know a solution?
    thanks
    bertl

    Hi,
    You can sort the Char.Values by doing settings in Query Designer :
    Say for 0calmonth :
    In its Display properties tab,You select appropriate options in
    Sort Char -> select the name
    sort by -> Key/Text
    Sort Direction -> Ascending/Descending.
    You will then have them in required order.
    ALso if you want it only for F4 help:
    In F4 help screen,you will see two arrow buttons next to Char. name. they are useful for sorting the values to either descending or ascending.
    Hope it helps:)

  • Sort Order problem in a cursor

    Hi,
    I have a cursor where the sort order needs to be specified dynamic. I have declared variables (say x and y) which contains the numbers. When I use them in the order by clause, though no compilation error, but the sorting does not occur.
    Eg. Cursor C1 is
    Select col1,col2
    from tab1
    where ...
    ORDER BY x (the value of x is 2).
    Your help is greatly appreciated. (This cursor is in Oracle Forms)
    Thanks

    How come this works:
    select samp1,samp2
    from   (select 'abc' samp1, 123 samp2 from dual union all
            select 'mno' samp1, 456 samp2 from dual union all
            select 'def' samp1, 3 samp2 from dual union all
            select 'pqr' samp1, 12 samp2 from dual union all
            select 'jkl' samp1, 64 samp2 from dual union all
            select 'stu' samp1, 10 samp2 from dual union all
            select 'vwx' samp1, 88 samp2 from dual union all
            select 'ghi' samp1, 7 samp2 from dual union all
            select 'yzz' samp1, 1 samp2 from dual
            ) testdata
    order by &x
    Enter value for x: 2
    old  12: order by &x
    new  12: order by 2
    SAM      SAMP2
    yzz          1
    def          3
    ghi          7
    stu         10
    pqr         12
    jkl         64
    vwx         88
    abc        123
    mno        456
    9 rows selected.
    select samp1,samp2
    from   (select 'abc' samp1, 123 samp2 from dual union all
            select 'mno' samp1, 456 samp2 from dual union all
            select 'def' samp1, 3 samp2 from dual union all
            select 'pqr' samp1, 12 samp2 from dual union all
            select 'jkl' samp1, 64 samp2 from dual union all
            select 'stu' samp1, 10 samp2 from dual union all
            select 'vwx' samp1, 88 samp2 from dual union all
            select 'ghi' samp1, 7 samp2 from dual union all
            select 'yzz' samp1, 1 samp2 from dual
            ) testdata
    order by &x
    Enter value for x: 1
    old  12: order by &x
    new  12: order by 1
    SAM      SAMP2
    abc        123
    def          3
    ghi          7
    jkl         64
    mno        456
    pqr         12
    stu         10
    vwx         88
    yzz          1
    9 rows selected.Isn't this what is wanted?
    -Marilyn

  • Sort Order Definitions:

    looking for help in the sort order choices and how each one works to sort in grid view. Some are self evident but others I am not sure of...like PICK and EDIT COUNT.
    can anybody define how they sort...not finding any info in the LR4 help system
    Thnak you.

    Thank you for the tip. I've modified my Formular in order to look like this:
    // Declare and initialize variable
    Local NumberVar ProjectNo;
    // Extract Main project no out of database field and store it in local var.
    ProjectNo := ToNumber(
                    Left(
                        {Dienstleistungen.verweistAuf},
                        InStr({Dienstleistungen.verweistAuf},'-') - 1
    if (ProjectNo) = 0 then
    0
    else
    ProjectNo
    But this produces the same effect as above. Still no luck. Did I miss something?
    Thank you.

  • Update a list item based sort order of created by column value

    HI
    using powershell script how to sort a list column before update a list  item.
    here i created a document library and uploaded some documents and update ProcessNo column based sort order of created column
    value.
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:91" $listName = "Courts"
    Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    $list = $web.Lists[$listName] 
    $items = $list.items
    Go through all items
    foreach($item in $items)
    $item["ProcessNo"] = 1
    $item.Update()
    $web.Dispose()

    Hi,
    According to your description, my understanding is that you want to sort the list items order before updating items using PowerShell.
    I suggest you can use the Sort-Object command to sort the list items.
    Here are some detailed articles for your reference:
    Better SharePoint Lists and List Items in PowerShell
    Sort-Object
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Display number of entries per sort order

    G'day all.
    Does anybody know how I can display number of entries per sort order in
    ALV grid.
    i.e. ABC 2000
    2000
    2000
    3 (entries) 6000
    DEF 1000
    HIJ 2000
    2 (Entries) 3000
    5 (Total Entries) 9000

    Hi,
    The way I did it I used "AT END OF " statement and added my amount to a
    variable and then move my variable in work area and then modified your
    internal table from work area transporting that field or depending on
    your requirement that you need to add a separate line for totals append
    the internal table which you are going to use it for first display. Then
    after the set_table_for_first_display I added the alv_build_sort
    criteria. And call method alv_list->set_sort_criteria exporting the
    internal table i_sort.
    Cheers,
    Chaitanya

  • Interactive sort order display

    How can I display the order in which the user has clicked the report columns using interactive sort feature?
    If I apply the interactive sort on two columns and user sorts first Column1 and then (holding Shift key) sorts Column2, then it is different sort order than when he clicks Column2 and then Column1.
    Unfortunately in both these situations, the column headers look the same. You can't tell which column used clicked first (which column is first in the sort order).
    I want to display the sort order before the tablix:
    - sort order: Column1, Column2
    or
    - sort order: Column2, Column1

    Hi jedrekc,
    According to your description, you have two columns with interactive sort in your report. Now you want to display the sequence of sorting so that you can see which column is sorted first. Right?
    In Reporting Service, we don’t have any variable or function to record some kind of event like you click on interactive sort icon. That means we can’t catch this click action so that it’s impossible to display the column names based on sorting order. So
    currently, your goal can’t be achieved.
    However, this kind of requirement is sensible and useful. I would recommend you to submit it as a feedback to the Microsoft Connect at this link https://connect.microsoft.com/SQLServer/Feedback.
    This connect site will serve as a connecting point between you and Microsoft, and ultimately the large community for you and Microsoft to interact with. Your feedback enables Microsoft to offer the best software and deliver superior services, meanwhile you
    can learn more about and contribute to the exciting projects on Microsoft Connect. 
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • TopN sort order modification dinamically

    Hi there,
    I'm a newbie on obiee so maybe I'm asking something obvious but,...
    I have a topN table which could by different values, ie: success Rate and Volume. the colum which contains the topN funcion sorted as ascending. Now if we sort by volume we get the topn(data.volumen,@{topN}{30}) to show the best first, when we select succes rate we do topn(data.volumen*-1,@{topN}{30}), this approach works fine for us.
    A new requirement is to change dinamically the sort order, to do it I have created a prompt like this:
    SELECT case when 1=0 then dummy.dummy else 'Ascending' end FROM subjectArea UNION ALL
    SELECT case when 1=0 then dummy.dymmy" else 'Descending' end FROM subjectArea
    and stores the result in a presentation variable, when I try to use the variable on a column trying to select the order with case and 2 topN funtion I get an error, I also have tried to use a fake coumn and always get an error. Do you know if is there any way to transform the Ascending/descending to a -1/1 to do something like topn(data.volumen*@{order},@{topN}{30})
    thanks for your help,
    Fernando

    Hi Fernando,
    Is this 11g? If so, you don't need to use a CASE statement in the prompt. Use a "variable prompt" to set the presentation variable and populate this with custom values, 'Ascending' and 'Descending'.
    You should then be able to use this presentation variable and a CASE statement within the column that you're sorting on. What is the error that you're getting?
    JB

  • Change the sort order (ascending/descending) based on parameter field

    I have created a formula on a subreport to change sorting based on variables.
    select {?Pm-@Sorting}
    case "property_type_desc ASC" :
    {owned_property.property_type_desc}
    case "property_type_desc DESC" :
    {owned_property.property_type_desc}
    default:
    ({owned_property.property_type_cd}; )
    how can I change the sort order ascending and descending using the formula??
    Thanks, Jessica

    Try this
    1. Create a parameter with 2 default values in the picklist: Descending and Ascending.
    NOTE:
    In Crystal Reports version 5 or 6, it is not possible to have a pick a parameter value from a list. The user must enter a specific value, guided by the prompting text. For example : To Sort in Ascending order type A, to sort in Descending order type D.
    u2022 On the 'Insert' menu, click 'Parameter', then click 'New'.
    u2022 Type the name and prompting text for the parameter in the corresponding boxes.
    u2022 In the 'Type' box, click 'String'.
    u2022 Click 'Set Default'.
    u2022 In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.
    u2022 Repeat the above step for 'Ascending'.
    u2022 Click 'OK', then click 'OK' again to return to the report.
    2. Create 2 formulas based on the field you want to change the sort direction on:
    u2022 On the 'Insert' menu, click 'Formula', then click 'New'.
    u2022 Create this formula:
    @Asc
    If {?Parameter} = "Ascending" then
    u2022 Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.
    u2022 Click 'New' and create this formula:
    @Des
    If {?Parameter} = "Descending" then
    u2022 Save this formula and close the Formula Editor.
    u2022 Click 'Close' to return to the report.
    4. Sort the report based on these two formulas.
    u2022 On the 'Report' menu, click 'Sort Records'.
    u2022 In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Ascending'.
    u2022 In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Descending'.
    u2022 Click 'OK' to return to the report.
    Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.
    Regards,
    Raghavendra

  • Define sort order in searchhelp...

    I have remade the premk searchhelp and I was wondering If I could influence the sort order of the fields displayed.
    it sorts by default on the first field in the output list but I also want to sort it on a second column.
    I can't find in the selopt tables in function HRMC_PREM_EXIT where the sort order is defined or whether it's sap standard to only sort on the first field ? can I influence the sort order in the view perhaps ?
    kind regards
    arthur de smidt
    Edited by: A. de Smidt on Jul 28, 2008 10:44 AM

    Hello Arthur De Smidt,
    In the PARAMETER_SORT variable, take the field names
    Eg.:
    If you want a table to be sorted by carrid and connid,
    data:
      w_sort(20) type c value 'CARRID CONNID'.
    Now pass w_sort to the parameter  PARAMETER_SORT in the FM.
    Dont call the FM twice. Use a character work variable which has the field names separated by space and pass that work variable to the FM.
    Hope it helps you.
    Get back for further help.
    Regards
    Indu.

  • Message sort order

    I want to change the default message sort order so messages are listed by most recent first, instead of oldest first in the mailbox.
    I've been reading about modifying the message list here:
    http://docs.sun.com/source/816-6010-10/uicst.htm#13511
    and just want to confirm that if I modify the meSortOrder variable in the main.js file, will that change the default message list for all existing mailboxes displayed in webmail?
    Also, does anyone know for sure whether the variable to list the newest messages first is meSortOrder=last or meSortOrder=L ???
    My system specs:
    iPlanet Messaging Server 5.1 Patch 1 (built Jun 6 2002)
    libimta.so 5.1 Patch 1 (built 06:07:28, Jun 6 2002)
    HP-UX wwcc B.11.00 A 9000/879 674411361 two-user license
    Thank you - Forrest

    Yes, thank you Jay - and I am working towards that now - in part due to the information you shared.
    But the question I am faced with will remain, can I change the default webmail message display from "oldest first" to "oldest last" on the system level. And at this time, I'm not sure if a newer version will change that default.
    So, from what I've read, in part from this Messenger Express customization guide:
    http://docs-pdf.sun.com/816-5986-10/816-5986-10.pdf
    you need to change the SortOrder variable to 'last' in the main.js.
    From my tests, this does not work. There seem to be preset variables options, and 'last' is not one of them. However, there are two more variables that look like they could affect this change: 'sorting' and 'orgSort'. Does anyone know how to change this setting to have the newest messages displayed first?
    Thank you,
    Forrest

  • Album sort order PSE11 - is it by design ?

    When experimenting with the sort order of albums in PSE11, I was surprised to see that in some albums, changing the sort order from 'oldest' to 'newest' did not produce any effect.
    The reason of this probably lies in the menu /preferences/general :
    If you have only pictures taken the same day, the above setting will still show 'oldest first' even you choose 'newest first' for album order.
    I believe that the most used order is 'album order' and that the 'newest first' is very rare.
    I can understand the option to browse 'oldest first within each day' when in 'newest first' in thumbnail view.
    However, I wonder if that option makes sense to sort an album ?
    Was it by design ?
    If it were me...
    I would not use that preference for an album,
    and...
    I would add the option to sort by filename and caption.

    Figured it out. I added "Various Artists" in the Album Artist field for every track and it then sorted them all together.

  • Order of variables in calculation manager 11.1.2.2 rulesets

    Hi,
    We are in the process of migrating all our 11.1.2.1 HBR Sequences to 11.1.2.2 Rulesets. While migrating the sequences to rule sets I came across an issue where the order of the variables displayed in the Ruleset designer "Variables" tab doesn't match the order of the rules in the rulesets. This is not the case with the HBR sequences in EAS where the variables are associated with rules with valid Index.
    Eg:
    EAS
    Order of rules in the Sequence: RuleA, RuleB, RuleC
    Order of variable in the Launch Variables Tab: VarA1,VarA2,VarB1,VarB2,VarC1 ( Assuming that VarA1,VarA2 and VarB1,VarB2 and VarC1 are variables associated to rules A,B and C respectively.
    Calc Manager
    Order of rules in the Sequence: RuleA, RuleB, RuleC
    Order of Variables in the Variables tab: VarC1,VarA1,VarA2,VarB1,VarB2 ( Random)
    My case is more complex because I'm running the same rule for different values for a particular runtime prompt 38 times and they have to run in a order. Now I couldn't associate the rule with the variable that I'm changing.
    I tried creating the sequence from scratch rather than importing it from 11.1.2.1 but no luck. Please help!

    Raj,
    I opened up the .xml file from the Ruleset export and the "Seq_index"( which specifies the rule to which the variable belongs) and "seq" number (which specifies the variable order) are in the correct order as the rules order in the ruleset. But still the variables are not displayed in correct order in the "Variables" tab of the ruleset.
    Eg.
    Rule order in the rule set: R1,R2,R3
    <variable_references>
    <variable_reference id="3772" name="*R1v1*">
    <property name="seq"> *2* </property>
    <property name="seq_index"> *1* </property>
    </variable_reference>
    <variable_reference id="3770" name="*R1v2*">
    <property name="seq"> *3* </property>
    <property name="seq_index"> *1* </property>
    </variable_reference>
    <variable_reference id="3771" name="*R2v1*">
    <property name="seq"> *4* </property>
    <property name="seq_index"> *2* </property>
    </variable_reference>
    <variable_reference id="3773" name="*R2v2*">
    <property name="seq"> *5* </property>
    <property name="seq_index"> *2* </property>
    </variable_reference>
    <variable_reference id="3774" name="*R3v1*">
    <property name="seq"> *6* </property>
    <property name="seq_index"> *3* </property>
    </variable_reference>
    Displayed order of variables in calcmanager: R2v1,R2v2,R1v1,R1v2,R3v1 (Note that the variables belonging to the same rule are showing up in correct order).
    It will be very difficult to me to modify the seq# and index in the xml file as I have 40 rulesets with each having 20 rules and around 5 variables for each rule.
    Thanks,
    Swaraj.

  • How do I get Iphoto to preserve the sort order when I transfer an album?

    Here's my problem. I carefully sorted my album of 230 photos manually. Each photo was then numbered from 1 to 230.   Then I used IPhoto Library Manager to transfer this album someplace else -- to my desktop, to a thumb drive, to Dropbox---   In every case, when I did that, the photos themselves transfered just fine,  but the sort order I had so carefully constructed has fallen apart and cannot by retrieved. Even  when I  close and then reopen an Album I have transferred to my Desktop, it loses its sort order.  This is driving my crazy  because I need to transfer this album so that it preserves the slideshow I have designed for it. A slideshow, of course, demands preserving the order of the slides.
    In short, how can I preserve the sort order of an album when I transfer it out of one library to another?

    If you're transferring to another library, why are you exporting to the Finder (which is what Desktop, thumbdrive and DropBox are). This doesn’t understand manual sorting from iPhoto.
    Here's one (of several) way(s) to do what you want:
    Make an Album of the photos, then drag the pics into your preferred order.
    Then Photos Menu: Batch Change -> Set Title to Text "John's Birthday", for instance, and tick the box to append a number to each Photo. Now your photos are titled 'John's Birthday 001, John's Birthday 002 ... etc'
    Then File -> Export and in the Export dialogue set the Filename to "Use Title"
    Sort on Filename in the FInder and you end up with a folder full of images in the same order as the Album in iPhoto.

Maybe you are looking for