Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Ordering by highest value

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default Ordering by highest value

    i am trying to write a simple script that ulls some score data froma table then echo score according to the highest value:

    PHP Code:
    $query "SELECT * FROM score ";
    $result mysql_query($query);

    /* This just gets the number of rows in the Query - It's just a check to see if the ipc exists - If not it echos out an error statement. */
    $numR mysql_num_rows($result);

    // If the number of rows is not equal to one then it echos out an error statement - ipc not in Database.

      
    if ($numR == 1) {
      if(
    $row mysql_fetch_array($result));
    //now how do i check score1 to 16 to find out whick is the highest and echo //accordingly 

    your help is appreciated
    Last edited by Arch_Angel; Feb 27, 2007 at 04:07 PM. Reason: added PHP code formatting
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Have you tried selecting the MAX(score) FROM the table?

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    no what i want is to select all the score but equo them according to the highst value
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    How about ORDER BY DESC?

  5. #5
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    this still will not work. Al teast i dont think. What i want is to order based on value. The highest score is echod first, second highest echoed second and so forth until the 16 th value.
    "...men are that they might have joy."
    Nephi

  6. #6
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    I may be a bit off base here, but I think that is what the ORDER BY DESC does. I could be wrong, but it orders by the highest value.

    SQL ORDER BY

    This looks a lot like what you want. Highest value to lowest value.

  7. #7
    Join Date
    Jan 2007
    Posts
    164
    Rep Power
    18

    Default

    Quote Originally Posted by Blunty Killer View Post
    I may be a bit off base here, but I think that is what the ORDER BY DESC does. I could be wrong, but it orders by the highest value.

    SQL ORDER BY

    This looks a lot like what you want. Highest value to lowest value.
    I agree, just order it in the SQL statement

  8. #8
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default Output name value pairs

    ok i totally forgot that it was so easy to order data. What i want to do now is echo in name value pairs :

    PHP Code:
    <?php
      
    include_once("conn.php");

    $f = ($_GET["f"]);

    $query "SELECT side, CONCAT(twins, "      ", tloses) from summary ORDER BY twins ASC";
    $result mysql_query($query);


    $numR mysql_num_rows($result);



      if (
    $numR == 1) {
      if(
    $row mysql_fetch_array($result));
    now i want to
    PHP Code:
    echo "&side1 = $some php script[]";//hiqhest scoring side name

    echo "&side2 = $some phpscript[]";//next highest scoring side name etc.

    echo "&info1 = $some php script[]";//score details about hiqhest scoring side. This has the concat info twins and tloses

    echo "&info2 = $some phpscript[]";//score details about next hiqhest scoring side. This has the concat info twins and tloses 

    something like that. Any help is appreciated.
    Last edited by Arch_Angel; Feb 27, 2007 at 04:09 PM. Reason: added PHP code formatting
    "...men are that they might have joy."
    Nephi

  9. #9
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    This is what i have so far , but i am getting a error with the sql please take a look:

    <?php

    include_once("conn.php");

    $f = ($_GET["f"]);
    $query = "SELECT side, CONCAT(twins, " ", tloses) AS stats, FROM summary ORDER BY twins ASC";
    $result = mysql_query($query) or die(mysql_error());
    $numR = mysql_num_rows($result);
    if ($numR = 1) {
    echo"success=1";
    $statsarray = array();
    $sidearray = array();
    $x = 0 // array index
    //collect returned results in associtive manner
    while($result = mysql_fetch_assoc($result)){
    $statsarray[$x] = $result['stats'];
    $sidearray[$x] = $result['side'];
    $x++;
    }
    //to display

    $loopcontrol = count($side);

    for($a = 0; $a<$loopcontrol; $a++){
    echo $sidearray[$a] . " " . $statsarray[$a];
    }
    }
    else
    {
    echo( "success=0" );
    }

    // Clean up
    mysql_close($dblink);

    ?>

    Now the error i am getting is this:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/www//score.php on line 6.
    This is line 6:
    $query = "SELECT side, CONCAT(twins, " ", tloses) AS stats, FROM summary ORDER BY twins ASC";

    As for as i can figure the sql looks good but i am getting this error.
    "...men are that they might have joy."
    Nephi

  10. #10
    Join Date
    Jan 2007
    Posts
    164
    Rep Power
    18

    Default

    Quote Originally Posted by leocrawf View Post
    This is what i have so far , but i am getting a error with the sql please take a look:

    <?php

    include_once("conn.php");

    $f = ($_GET["f"]);
    $query = "SELECT side, CONCAT(twins, " ", tloses) AS stats, FROM summary ORDER BY twins ASC";
    $result = mysql_query($query) or die(mysql_error());
    $numR = mysql_num_rows($result);
    if ($numR = 1) {
    echo"success=1";
    $statsarray = array();
    $sidearray = array();
    $x = 0 // array index
    //collect returned results in associtive manner
    while($result = mysql_fetch_assoc($result)){
    $statsarray[$x] = $result['stats'];
    $sidearray[$x] = $result['side'];
    $x++;
    }
    //to display

    $loopcontrol = count($side);

    for($a = 0; $a<$loopcontrol; $a++){
    echo $sidearray[$a] . " " . $statsarray[$a];
    }
    }
    else
    {
    echo( "success=0" );
    }

    // Clean up
    mysql_close($dblink);

    ?>

    Now the error i am getting is this:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/www//score.php on line 6.
    This is line 6:
    $query = "SELECT side, CONCAT(twins, " ", tloses) AS stats, FROM summary ORDER BY twins ASC";

    As for as i can figure the sql looks good but i am getting this error.
    Use single quotes inside your quotes i.e. "SELECT side, CONCAT(twins, ' ', tloses) AS stats, FROM summary ORDER BY twins ASC" or otherwise you will need to escape the double quotes

Posting Permissions

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