Jump to content

Returned values displayed differently?


woolyg

Recommended Posts

Hi all,

 

I've got a function in PHP that calls values from a MYSQL DB, and it returns numbers.

 

(eg. - Woolyg - 14)

 

Is there a way in PHP to substitute these numbers for worded values? So say if the function returned values 1-10 it displays the word 'Useless'... 10-20 displays 'Average'... and 20-30 displays 'Awesome'..?

 

Anyone got any idea?

Cheers,

Woolyg

Link to comment
https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/
Share on other sites

<?php
function rating($score)
{
    if ($score >= 20)
        $res = 'Awesome';
    elseif ($score >= 10)
        $res = 'Average';
    else
        $res = 'Useless';
    return $res;
}

$score = 15;

echo rating($score)
?>

Cool, thanks guys - I'll put it into practise and see what I can come up with.

 

Do you think this would work for multiple populated numbers?

 

Say, if I had a table with a number of entries that I was calling:

 

ID  Name    Value1  Value2  Value3

1    Woolyg    14        7          28

 

and used

 

$query = mysql_query(SELECT * FROM table");
$show = mysql_fetch_ros($query);

if($show){
echo "$show[1]<br>";
echo "$show[2]<br>";
echo "$show[3]<br>";
echo "$show[3]<br>";
}

 

..would that work? - And additionally, would I be able to use the same code barand posted above and link it to a different query?

 

 

To explain above:

The query returns a row, from which I select returned values 1, 2, 3 and 4

 

If $show[1] returned the value 5, I'd like to display the word "Useless"

If $show[2] returned the value 15, I'd like to display the word "Average"

If $show[3] returned the value 25, I'd like to display the word "Awesome"

 

 

.. get me? I hope my code-addled brain is able to explain properly..

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.