Announcement

Collapse
No announcement yet.

displaying mysql query correctly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Helza
    replied
    PNN: It works perfectly, thanks

    Leave a comment:


  • Helza
    replied
    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

    Leave a comment:


  • scoutt
    replied
    what is _QueryRow?

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

    Leave a comment:


  • Scott MacVicar
    replied
    Try changing the query

    so

    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
    $scores[total]
    or
    $scores[min_score_0]

    Leave a comment:


  • Helza
    replied
    print_r($scores) outputs the following:



    Array
    (
    [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.

    Leave a comment:


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

    Leave a comment:


  • Helza
    started a topic displaying mysql query correctly

    displaying mysql query correctly

    Hi,

    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..
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X