No announcement yet.

displaying mysql query correctly

  • Filter
  • Time
  • Show
Clear All
new posts

  • displaying mysql query correctly


    I have a question, i have an mysql query which returns an associative array which looks like this:

    $scores = _QueryRow("SELECT COUNT(*), MIN(score_0), MAX(score_0), FORMAT(AVG(score_0),2), MIN(score_1), MAX(score_1), FORMAT(AVG(score_1),2), MIN(score_2), MAX(score_2), FORMAT(AVG(score_2),2), MIN(score_3), MAX(score_3), FORMAT(AVG(score_3),2), MIN(score_4), MAX(score_4), FORMAT(AVG(score_4),2), MIN(score_5), MAX(score_5), FORMAT(AVG(score_5),2)
    FROM reviews
    WHERE categoryid='$categoryid'
    AND productlistid='$productlistid'");

    now in $scores are the min, max and average values of score_0 till score_5

    with print_r($scores) i can see that it is filled with the correct values..

    however i want to display these values in a more nicer way but i can'tt seem to get these values out of my associative array, could anyone help please..

    currently i use this line, but it doesn't work:

    for ($e=0;$e<5;$e++){
    echo "score $e: ".$scores[MIN({score_.$e})]

    even if i try using just
    echo "test: ". $score[MIN(score_0)]."<BR>";

    it won't work.. how do you get associative array names like these MIN() and MAX() displayed?

    Thanks in advance for the help..

  • #2
    Can you print out the array and post it here.
    Scott MacVicar

    My Blog | Twitter


    • #3
      print_r($scores) outputs the following:

      [COUNT(*)] => 2
      [MIN(score_0)] => 1
      [MAX(score_0)] => 4
      [FORMAT(AVG(score_0),2)] => 2.50
      [MIN(score_1)] => 0
      [MAX(score_1)] => 9
      [FORMAT(AVG(score_1),2)] => 4.50
      [MIN(score_2)] => 1
      [MAX(score_2)] => 6
      [FORMAT(AVG(score_2),2)] => 3.50
      [MIN(score_3)] => 0
      [MAX(score_3)] => 3
      [FORMAT(AVG(score_3),2)] => 1.50
      [MIN(score_4)] => 1
      [MAX(score_4)] => 2
      [FORMAT(AVG(score_4),2)] => 1.50
      [MIN(score_5)] => 0
      [MAX(score_5)] => 8
      [FORMAT(AVG(score_5),2)] => 4.00

      (the scores themselves are correct)
      Last edited by Helza; Wed 26 Jun '02, 6:11am.


      • #4
        Try changing the query


        COUNT(*) AS total, MIN(score_0) AS min_score_0, MAX(score_0) AS max_score_0, FORMAT(AVG(score_0),2) AS avg_score_0

        and so forth

        then you can use
        Scott MacVicar

        My Blog | Twitter


        • #5
          what is _QueryRow?

          also if you are doing min and max in the query why do it it in php also?


          • #6
            Thanks PPN, i'll try it as soon as i get home.. i hope that works

            scoutt: _QueryRow is an function i've create, it takes the String i give it and becomes an mysql string. ones it gets the result it will perform some error checking/outputting..

            saves alot of code writing


            • #7
              PNN: It works perfectly, thanks


              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.