twilitegxa Posted August 17, 2009 Share Posted August 17, 2009 How can I add soem text to display to this variable? I currently have an if statement to make the variable diaply as blank if the value is null or zero, but if the variable does contain a value, I want the text "(for Sailor Scout Attack)" to display after the value. Like here is the variable and how I want it to display, I just don't have it added to the variable right: acv2 = $derived_info['acv2'] + '(for Sailor Scout Attack)'; Here is the rest of the statement so you can see the if statement: //gather derived values $get_derived = "select * from derived_values where identity = '$identity'"; $get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error()); while ($derived_info = mysql_fetch_array($get_derived_res)) { $health = $derived_info['health']; $energy = $derived_info['energy']; $acv1 = $derived_info['acv1']; $acv2 = $derived_info['acv2']; $dcv1 = $derived_info['dcv1']; $dcv2 = $derived_info['dcv2']; $total_cp = $derived_info['total_cp']; if($health == 0 || $health == '0' || $health == null){$GLOBALS['health'] = "";} if($energy == 0 || $energy== '0' || $energy == null){$GLOBALS['energy'] = "";} if($acv1 == 0 || $acv1 == '0' || $acv1 == null){$GLOBALS['acv1'] = "";} if($acv2 == 0 || $acv2 == '0' || $acv2 == null){$GLOBALS['acv2'] = "";} if($dcv1 == 0 || $dcv1 == '0' || $dcv1 == null){$GLOBALS['dcv1'] = "";} if($dcv2 == 0 || $dcv2 == '0' || $dcv2 == null){$GLOBALS['dcv2'] = "";} if($total_cp == 0 || $total_cp == '0' || $total_cp== null){$GLOBALS['total_cp'] = "";} Link to comment https://forums.phpfreaks.com/topic/170685-solved-adding-text-to-a-variable-already-defined/ Share on other sites More sharing options...
KevinM1 Posted August 17, 2009 Share Posted August 17, 2009 String concatenation uses a '.' as its operator, like so: echo $myValue . " some text"; Link to comment https://forums.phpfreaks.com/topic/170685-solved-adding-text-to-a-variable-already-defined/#findComment-900190 Share on other sites More sharing options...
kickstart Posted August 17, 2009 Share Posted August 17, 2009 Hi Something like this? $acv2 = (($derived_info['acv2'] != '') ? $derived_info['acv2'] . '(for Sailor Scout Attack)' : ''); You could also use empty() instead of checking for ''. All the best Keith Link to comment https://forums.phpfreaks.com/topic/170685-solved-adding-text-to-a-variable-already-defined/#findComment-900191 Share on other sites More sharing options...
MatthewJ Posted August 17, 2009 Share Posted August 17, 2009 if($acv2 == 0 || $acv2 == '0' || $acv2 == null){$GLOBALS['acv2'] = "";} else { $acv2 .= " for Sailor Scout Attack"; } Link to comment https://forums.phpfreaks.com/topic/170685-solved-adding-text-to-a-variable-already-defined/#findComment-900192 Share on other sites More sharing options...
twilitegxa Posted August 17, 2009 Author Share Posted August 17, 2009 Thanks, everyone. I did this and it worked: $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)'; Link to comment https://forums.phpfreaks.com/topic/170685-solved-adding-text-to-a-variable-already-defined/#findComment-900276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.