SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast azblkcobra's Avatar
    Join Date
    Nov 2004
    Location
    Phoenix
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function timing out

    I have this function I am trying to optimize but it keeps timing out and I can not set run time on my remote server. Basically what am trying to do is select a member then match them against other members in the dbase. Now instead of cycling through all members am trying to just cycle through members that meet a certain criteria like sexual preference or race. The function is given below:

    PHP Code:
    function match_makelist1()
        {
            
    $highest=0;
            global 
    $set_match_val;

            
    $res_user $this->db->Q("select * from users where username = '" $this->person "'");
            
    $sql "delete from matchprofiles where username_p1 = '" $this->person "'";
            
    $res_del $this->db->Q($sql);

            while(
    $row1=mysql_fetch_array($res_user))
            {
                
    $genderlook $row1["lookingf_1"]; //check members gender preference
                
    $ethnicitylook $row1["lookingf_17"]; //check members ethnic preference
                
    $sql1="AND f_17=$ethnicitylook"//sql add on            
              
    if ($ethnicitylook == )
                {
                    
    $sql1 "AND f_17 > 0 ";
                } 
                

                
    $res $this->db->Q("select * from users where username != '" $this->person "' AND f_1 = '$genderlook' ".$sql1."  ");
                   
                

                
    $num_total $this->db->NumRows($res);
                
                while(
    $row=mysql_fetch_array($res))
                {
                        
    $points 0;    
                        
    $username $row["username"];

                        
                        
                        
    $res2 $this->db->Q("select * from questions");
                        
                        while(
    $questionRow=mysql_fetch_array($res2))
                        {
                            
    $q_field $questionRow["q_field"];
                            
    $q_question $questionRow["q_question"];
                            
    $q_size $questionRow["q_size"];
                            
    $q_type $questionRow["q_type"];
                            
    $q_catdescr $questionRow["q_catdescr"];
                            
    $q_seq $questionRow["q_seq"];
                            
    $q_page $questionRow["q_page"];
                            
    $q_mand $questionRow["q_mand"];
                            
    $q_weigth $questionRow["q_weigth"];            
                            
    $q_looking $questionRow["q_looking"];
                            
    $q_between $questionRow["q_between"];
                            
                            
    $field "f_" $q_field;
                            
    $value $row[$field];
                            if (
    $q_looking)
                            {
                                if (
    $q_between)
                                {
                                        
    $field "betweenFromf_" $q_field;
                                        
    $orig_value_from $row1[$field];
                                        
                                        
    $field "betweenTof_" $q_field;
                                        
    $orig_value_to $row1[$field];
                                        
                                }
                                else 
                                {
                                    
    $field "lookingf_" $q_field;
                                    
    $orig_value $row1[$field];
                                }
                            }
                            else 
                            {
                                
    $field "f_" $q_field;
                                
    $orig_value $row1[$field];
                            }
                            
                            if (
    $q_between)
                            {
                                if (
    $orig_value_from<$value AND $orig_value_to>$value)                                          
                                {
                                    
    $points $points + (1*$q_weigth);
                                    
    //print "<hr>Points $orig_value_from $value $orig_value_to";
                                    
                                
    }
                                
    $highest $highest + (1*$q_weigth);
                            }
                            else 
                            {
                                
    $val_array split(",",$value);    
                                
    $orig_value_array split(",",$orig_value);
                                
                                
    $result array_intersect($val_array,$orig_value_array);
                                
                                
    $num count($result);
                                
    $num_max count($orig_value_array);
                                
                                
    $points $points + ($num*$q_weigth);
                                
    $highest $highest + ($num_max*$q_weigth);    
                            }                
                            
                        }

                        
                        

                        if (
    $points>$set_match_val)
                        {
                            
    $sql "insert into matchprofiles (username_p1,username_p2,score,highest) values ('".$this->person ."', '$username','$points','$highest')";
                            
    $res_ins $this->db->Q($sql);
                            
    //echo $sql . "<br>";
                            
    echo "<table><tr><td>" $this->person "</td><td>$username</td><td>$points</td><td>$ethnicitylook</td></tr></table> ";
                        }
                        
    $highest 0;
                    
                    
              
        

        }
        }
                
     } 
    now if I remove this line, it works fine. The problem is I need this line or something like it because option 8 is All or Doesnt matter so I need to check all profiles.
    PHP Code:
     if ($ethnicitylook == 
                { 
                    
    $sql1 "AND f_17 > 0 "
                } 
    Last edited by azblkcobra; Dec 11, 2005 at 14:49.
    AzBlk

    Why sleep when there is money to be made?

  2. #2
    SitePoint Guru enygmadae's Avatar
    Join Date
    Sep 2002
    Location
    Dallas, Tx.
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    silly question, but how many records in the DB have a value in f_17 greater than 0?
    Also, you might echo out that "select * from users where username !=..." query to be sure all the parts are there like they should be...
    PHP News, Views and Community: http://www.phpdeveloper.org

  3. #3
    SitePoint Enthusiast azblkcobra's Avatar
    Join Date
    Nov 2004
    Location
    Phoenix
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would say about half of them.
    AzBlk

    Why sleep when there is money to be made?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •