final60 Posted July 5, 2011 Share Posted July 5, 2011 Hi how can I echo one variable that will check the integer from the database and print its associated text. if($status_result ==0){echo "<P>PENDING</p>";}; if($status_result ==1){echo "<p>ACCEPTED</p>";}; if($status_result ==2){echo "<p>DECLINED</p>";}; sorry bit of a php noob! thanks for nany help P.S I have a similar column in database but with only 2 possible options 0 or 1, so I used the ternary operator: $quote_result2 = $quote_result == 0?'<p>PENDING</p>':'<p>SENT</p>' . But not sure best way to did it with more than 2 options. Quote Link to comment https://forums.phpfreaks.com/topic/241121-display-different-result-depending-on-mysql-number/ Share on other sites More sharing options...
gristoi Posted July 5, 2011 Share Posted July 5, 2011 there are a few ways to acomplish this. first is use an array: $status = array('PENDING','ACCEPTED','DECLINED'); echo '<p>'.$status[$status_result].'</p>; another ( and only if you know the output is a limited amount ) is a switch: $status = array('PENDING','ACCEPTED','DECLINED'); switch($status_result) { case 0: $result = 'PENDING'; break; case 1: $result ='ACCEPTED'; break; case 2: $result = 'DECLINED'; break; } echo '<p>'.$result .'</p>; personally I would use an array to acomplish this, as you may in the future need to do more dynamic actions with your arrays. Quote Link to comment https://forums.phpfreaks.com/topic/241121-display-different-result-depending-on-mysql-number/#findComment-1238491 Share on other sites More sharing options...
final60 Posted July 5, 2011 Author Share Posted July 5, 2011 thanks for your reply. That array didn't work in this instance. $status_result2 = array('PENDING','ACCEPTED','DECLINED'); echo $status_result2[$status_result]; while($row = mysql_fetch_assoc($query)) { $status_result = $row['status']; } currently the integer in status on database is 0. Quote Link to comment https://forums.phpfreaks.com/topic/241121-display-different-result-depending-on-mysql-number/#findComment-1238503 Share on other sites More sharing options...
final60 Posted July 5, 2011 Author Share Posted July 5, 2011 sorry my mistake. Putting it before the while loop! DOH Quote Link to comment https://forums.phpfreaks.com/topic/241121-display-different-result-depending-on-mysql-number/#findComment-1238510 Share on other sites More sharing options...
gristoi Posted July 5, 2011 Share Posted July 5, 2011 Whay have you got your output above and outside of your query result?????????????????? it should look like this: $status_result2 = array('PENDING','ACCEPTED','DECLINED'); while($row = mysql_fetch_assoc($query)) { $status_result = $row['status']; echo $status_result2[$status_result]; } Quote Link to comment https://forums.phpfreaks.com/topic/241121-display-different-result-depending-on-mysql-number/#findComment-1238512 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.