SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Help me!

Hybrid View

  1. #1
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me!

    Hi all, im having a little problem
    check this code and read below it:
    Code:
                $sql = "select choice1_hits, choice2_hits, choice3_hits, choice4_hits
                      from poll";
                $result = mysql_query($sql) or die (mysql_error());
                
                $row = mysql_fetch_array($result);
                
                $max = $row["choice1_hits"];
                if ($max < $row["choice2_hits"]) {
                      $max = $row["choice2_hits"];
                }
                if ($max < $row["choice3_hits"]) {
                      $max = $row["choice3_hits"];
                }
                if ($max < $row["choice4_hits"]) {
                      $max = $row["choice4_hits"];
                }
    I want to get the numbers from the greatest to the smallest, please help me in this... Any help is most appreciated.. thanks guys

  2. #2
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks from that code your just trying to draw out the max value instead of the greatest to smallest.

  3. #3
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, as i said, i need a way to get all of the values... then output them, please give me a piece of code! im in serious trouble

  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $array = array("Choice 1" => $row["choice1_hits"], "Choice 2" => $row["choice2_hits"], "Choice 3" => $row["choice3_hits"], "Choice 4" => $row["choice4_hits"]);
    sort($array"SORT_NUMERIC");
    reset($array);
    while (list (
    $key$val) = each ($array)) {
        echo 
    $key ': ' $val "<br />\r\n";


    From the PHP manual, modified a bit.
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks alot, i really appreciate ur help

  6. #6
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh... it didnt work! guys, this script is a poll.. i want to print the results frmo the highest to the lowest WITH their names! i have the names fetched from the $row, eexample
    $row["choice1"] => $row["choice1_hits"] etc. so please hepl me doing this...


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
  •