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 Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 23, 2007 Share Posted April 23, 2007 wanna post some code? Quote Link to comment 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) ?> Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.