Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Ordering by highest value

  1. #21
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    [QUOTE=leocrawf;295750]$query = "SELECT side, CONCAT(twins,' ', tloses) AS stats FROM summary ORDER BY twins ASC"; this is what i have and i am still getting error.

    this is the error:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www//wcc/score.php on line 15

    this is line 15:
    PHP Code:
    while($row mysql_fetch_assoc($result)){ //this is line 15
    $statsarray[$x] = $row['stats'];
    $sidearray[$x] = $row['side'];
    $x++;

    try using another variable.........
    Last edited by recursion; Mar 1, 2007 at 12:56 PM.
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

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

    Default

    Quote Originally Posted by leocrawf View Post
    $query = "SELECT side, CONCAT(twins,' ', tloses) AS stats FROM summary ORDER BY twins ASC";
    I'm no MySQL guru, but I think I read somewhere that if you want to concatenate strings with a separator, the proper function to use is the CONCAT_WS. Maybe the parser has a problem with those single quotes
    twins,' ', tloses
    there when parsing the string. Try it, couldn't hurt.
    Last edited by Blunty Killer; Mar 1, 2007 at 01:20 PM.

  3. #23
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    I think he's saying that that section is ok.

    I'm no mysql nor php guru, in fact I'm nowhere close but I think he's overwriting his $result variable with the individual rows fetched.

    http://www.techjamaica.com/forums/sh...3&postcount=21
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

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

    Default

    You're right, missed the 'result resource'.

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

    Default

    tried all your suggestions with CONCAT_WS and removed the 'result resource'. and got the same problem on line 15.
    "...men are that they might have joy."
    Nephi

  6. #26
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    Yo leo check the line above it sometimes the error is in that line or the one above it
    $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++;
    }
    As you can see you forgot to put the Semi Colon ( ; ) after $x=0

    Good Luck

    How yeh u joomla site bout Noni IT MADD

  7. #27
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    So that we dont repeat our selves let me post the full script with all the corrrections:

    <?php

    include_once("conn.php");

    $f = ($_GET["f"]);
    $query = "SELECT side, CONCAT_WS(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);

    ?>

    and i am still getting error. The error is :
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www//wcc/score.php on line 15
    "...men are that they might have joy."
    Nephi

  8. #28
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Quote Originally Posted by leocrawf View Post
    while($result = mysql_fetch_assoc($result)){
    $statsarray[$x] = $result['stats'];
    $sidearray[$x] = $result['side'];
    $x++;
    }

    and i am still getting error. The error is :
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www//wcc/score.php on line 15
    Based on the nature of the error, you are supplying it with something it doesn't like. Could be the $result which you are also changing by the mere fact that you are making it a result of the call to the function. Usually it's bad programming practice to use a variable as a return of a function that the variable itself is also a parameter.

    Recursion pointed out that you should change that variable. Did you? And if you did what were the results? Because based on that code snippet you still have the $result as a return value and also a parameter. I don't know if it is ok in php, but imagine the consequences of changing the variable in the function and also using it as a parameter.

    I would surely revisit recursion's suggestion.

    mysel_fetch_assoc also highlights a seperate variable for the return value, not to be the same as the parameter to the function.

    To underscore the danger of return value and parameter, imagine the following:

    function DoSomething(SomeParam : Variant) : Variant
    start
    SomeParam = SomeParam + SomeOtherVar
    Result = SomeParam
    finish

    Now...

    variable a = 1 and variable a will be used later in your program
    you call a = DoSomething(a)
    you know what happens? a is no longer 1! and your later code is broke because you changed the value of a by making it a return value and also the parameter. If you had b = DoSomething(a), then you could revisit the use of a without breaking code.

    From what I see, it looks like you have changed the result resource into an array, which is now no longer valid for the call to mysql_fetch_assoc()
    Last edited by Blunty Killer; Mar 1, 2007 at 05:12 PM.

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

    Default

    Ok i followed recusion's suggestion to change variable :

    while($row = mysql_fetch_assoc($result)){ //this is line 15
    $statsarray[$x] = $row['stats'];
    $sidearray[$x] = $row['side'];
    $x++;
    }

    now i get a blank screen. So result is echoed on screen. Any idea what is happening here.
    Last edited by leocrawf; Mar 2, 2007 at 11:37 AM.
    "...men are that they might have joy."
    Nephi

  10. #30
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    Quote Originally Posted by leocrawf View Post
    now i get a blank screen. So result is echoed on screen. Any idea what is happening here.
    a blank screen with results echoed on screen... id love to see that (printscreen), cuz its hard to imagine. blank and at the same time with results echoed.

    as regards 'what is happening here', check the line after // to display

    Quote Originally Posted by recursion View Post
    I'm no mysql nor php guru,
    ...dito

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

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

    $query "SELECT side, CONCAT_WS(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 0///////// CHANGED FROM : if ($numR = 1) ... which is an assignment and not a comparison
    {
        echo 
    "success = 1";
        
    $statsarray = array();
        
    $sidearray = array();
        
        
    //collect returned results in associtive manner
        
    while($rowData mysql_fetch_assoc($result))
        {
            
    $statsarray[] = $rowData['stats'];
            
    $sidearray[] = $rowData['side'];
        }
        
        
    //to display
        
    $loopcontrol count($sidearray); ///////// CHANGED FROM : $loopcontrol = count($side); ... which should = $numR

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

    // Clean up
    mysql_close($dblink);

    ?>
    it is far easier to dissect properly laid out code

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

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

    $query "SELECT side, CONCAT_WS(twins,' ', tloses) AS stats FROM summary ORDER BY twins ASC";
    $result mysql_query$query ) or die( mysql_error() );

    if ( 
    mysql_num_rows$result ) == ) die( "Fetch returned no results" );

    // display returned results from data in associtive array
    while( $rowData mysql_fetch_assoc$result ) ) echo $rowData["'side" ] . " " $rowData"stats" ];

    ?>
    Last edited by icymint3; Mar 2, 2007 at 04:55 PM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

Posting Permissions

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