how to sort data from customized fields?

Discussion in 'Customization & add-ons' started by zdr81, Nov 24, 2009.

  1. zdr81

    zdr81 New Member

    Joined:
    Sep 1, 2006
    Messages:
    9
    I'm trying to get a list of people who would allow their email address to be shown... I made a customized field for email visibility and the output looks like this:

    PHP:
    for ($i=1$i<450$i++)
    {
        
    $u = & $db->get_user(intval($i));

        global 
    $member_additional_fields;

        foreach ((array)
    $vars['data'] as $k=>$v)
            
    $u['data'][$k] = $v;
        foreach (
    $vars as $k=>$v){
            if (
    $k != 'data')
                
    $u[$k] = $v;
            
    sort($v);
        }

    if (
    $u[email_list_choice] == 'YES') {  print ($u[name_f]); echo " "; print ($u[name_l]); echo "<br>"; print ($u[email]); 
    echo 
    "<br>"; }
    }
    I'd like to sort it by name or by email but am not sure how to insert the sort function to do so. Any thoughts?

    Thanks
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Use this code instead:
    Code:
    $q = $db->query("select * from amember_members where email_list_choice='YES' order by email");
    while($u = mysql_fetch_assoc($q)){
      print ($u[name_f]); echo " "; print ($u[name_l]); echo "<br>"; print ($u[email]); 
    echo "<br>"; 
    }
    
    You must create email_list_choice field as SQL in order to get above working.
  3. zdr81

    zdr81 New Member

    Joined:
    Sep 1, 2006
    Messages:
    9
    Alexander,

    I'm actually using the customized fields to pull out data from the blob field and sort it out...

    One of the customized fields is - email_list_choice. If that is 'yes' then I'd like to list and sort out the members by their names, states, etc..

    It would be too much work to go back and create a new SQL field and re-enter all the values and add it into the signup page...
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Well this is really better to do this. I will explain let's say you have 1000 users if you leave things as you have now this will require 1000 select requests to database just to display this page. What if page will be loaded 1000 times a day? What if users database will be big?
    If you will recreate this field, page will be loaded only with single SQL query.
    You can create php script that will update this field once if you need an example I can provide it.

Share This Page