woolyg Posted April 23, 2007 Share Posted April 23, 2007 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 More sharing options...
boo_lolly Posted April 23, 2007 Share Posted April 23, 2007 wanna post some code? Link to comment https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/#findComment-235796 Share on other sites More sharing options...
Barand Posted April 23, 2007 Share Posted April 23, 2007 <?php function rating($score) { if ($score >= 20) $res = 'Awesome'; elseif ($score >= 10) $res = 'Average'; else $res = 'Useless'; return $res; } $score = 15; echo rating($score) ?> Link to comment https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/#findComment-235803 Share on other sites More sharing options...
boo_lolly Posted April 23, 2007 Share Posted April 23, 2007 i'd use barand's logic with a switch() statement. Link to comment https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/#findComment-235809 Share on other sites More sharing options...
woolyg Posted April 23, 2007 Author Share Posted April 23, 2007 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? Link to comment https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/#findComment-235816 Share on other sites More sharing options...
woolyg Posted April 23, 2007 Author Share Posted April 23, 2007 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.. Link to comment https://forums.phpfreaks.com/topic/48238-returned-values-displayed-differently/#findComment-235845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.