SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorting results into top 10

    Hey guys,

    I have a "system" designed which I am using for a "match making" site for valentines day. This takes one person(referred to as mainid in my php) and it compares them with every other person from a grade(this is for a school) and I display the results out of 30, so one person might be like 15/30, another might be 23/30, etc. With my current setup I have a result that comes out of my php like this:

    name=Seth::results=17name=Joseph::results=11
    This is just what I want, but now I need to be able to sort results into a top 10 type thing. I am thinking I need to use an array on this, but I'm not sure how to do it..Here's what I was thinking I would need to do in an array..

    1) somehow limit it to 20 entries(top10 matches, and then the person's name that is a top10 match)
    2) Once I get through the matches for each person, See if that person's matches number is higher than the lowest matches number on the array
    3) If the matches for this person is higher than the lowest match on the array, then replace that number and ID with the "new" one.

    I hope you can understand this:
    Code:
    <?php include('header.php');
    include('connect.php');
    $mainid = $_GET['id'];
    	/*
    	********************************************
    	Get main details to compare to others
    	********************************************
    	*/
        $sql = mysql_query("SELECT * FROM information WHERE ID='$mainid' LIMIT 1");
        $numrows = mysql_num_rows($sql);
    
        for ($i=0; $i <= $numrows; $i++)
        {
            while ($row = mysql_fetch_array($sql))
             {
    		   $sex = $row['sex'];
                for ($x=1; $x<=30; $x++)
                {
                    $a = "ques$x";
                    $$a = $row["ques$x"];
                }
            }
        }    // end main details..
    	/*
    	********************************************
    	Comparing with grade 10
    	********************************************
    	*/
    	$sql = mysql_query("SELECT * FROM information WHERE grade='10' AND sex != '$sex'");
        $numrows = mysql_num_rows($sql);
    	for ($b=1; $b <= $numrows; $b++)
        {
            while ($row = mysql_fetch_array($sql))
             {	
         		echo "name=".$row['firstname']."::";
                for ($x=1; $x<=30; $x++)
                {
                    $a = "nques$x";
                    $$a = $row["ques$x"];
                }
    
    		// Now Check if this person matches the other
    		 $results = 0; // This is the number of matches between the two
    				  if($ques1 == $nques1) $results += 1;
    				  if($ques2 == $nques2) $results += 1;
    				  if($ques3 == $nques3) $results += 1;
    				  if($ques4 == $nques4) $results += 1;
    				  if($ques5 == $nques5) $results += 1;
    				  if($ques6 == $nques6) $results += 1;
    				  if($ques7 == $nques7) $results += 1;
    				  if($ques8 == $nques8) $results += 1;
    				  if($ques9 == $nques9) $results += 1;
    				  if($ques10 == $nques10) $results += 1;
    				  if($ques11 == $nques11) $results += 1;
    				  if($ques12 == $nques12) $results += 1;
    				  if($ques13 == $nques13) $results += 1;
    				  if($ques14 == $nques14) $results += 1;
    				  if($ques15 == $nques15) $results += 1;
    				  if($ques16 == $nques16) $results += 1;
    				  if($ques17 == $nques17) $results += 1;
    				  if($ques18 == $nques18) $results += 1;
    				  if($ques19 == $nques19) $results += 1;
    				  if($ques20 == $nques20) $results += 1;
    				  if($ques21 == $nques21) $results += 1;
    				  if($ques22 == $nques22) $results += 1;
    				  if($ques23 == $nques23) $results += 1;
    				  if($ques24 == $nques24) $results += 1;
    				  if($ques25 == $nques25) $results += 1;
    				  if($ques26 == $nques26) $results += 1;
    				  if($ques27 == $nques27) $results += 1;
    				  if($ques28 == $nques28) $results += 1;
    				  if($ques29 == $nques29) $results += 1;
    				  if($ques30 == $nques30) $results += 1;
    	/*
    	********************************************
    	Right here is where I would think I would enter the array. $results is the number of matches between the two people, so I think I would sort through the array, checking if($results > any_number_in_array) then replace that number with this $results entry..
    	********************************************
    	*/
    
    	}
    }
    ?>

    I hope I explained it well enough, because I seem to have a problem doing that

    Thanks a bunch guys
    Last edited by Schwalbach; Jan 16, 2005 at 14:54.
    http://chaseschwalbach.com

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    I think I get what you mean!

    On the query that echos the results, order by result either ascending (ASC) or descending (DESC).
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •