jacko_162 Posted March 19, 2010 Share Posted March 19, 2010 i use the following code to check if something is contained within an array; <?php echo (in_array("test1",$arr) ? "<tr><td> </td><td> </td><td> </td></tr>" : ''); ?> these echo commands work great. now in each of the 3x <td></td> i need the following: <td>TEXT HERE</td> <td><?php echo $test1 ?>ppt</td> <td><?php $val1 = 1.022; //----- Lowest Value $val2 = 1.027; //----- Highest Value $val3 = $test1; //----- Test Value (change number accordingly) if (($val3 > $val1) && ($val3 < $val2)) {echo '<img src="img/bullet_green.png" alt="" width="8" height="8" />';} else {echo '<img src="img/bullet_red.png" alt="" width="8" height="8" />';} ?></td> i get all types of errors with syntax when i include the above 3 code snippets into the top one. i have changed all the "" to '' but to no avail. can someone help me to create 1 PHP snippet with all the above please? Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/ Share on other sites More sharing options...
litebearer Posted March 19, 2010 Share Posted March 19, 2010 Pehaps this may help... <?PHP $val1 = 1.022; $val2 = 1.027; $val3 = 1.023; ?> <table> <tr> <td>Value 1</td><td><?PHP echo $val1; ?></td> <td>Value 2</td><td><?PHP echo $val2; ?></td> <td>Value 3</td><td><?PHP echo $val3; ?></td> <td>Color</td> <td> <?PHP if (($val3 > $val1) && ($val3 < $val2)) { echo '<img src="img/bullet_green.png" alt="green" width="8" height="8">'; }else{ echo '<img src="img/bullet_red.png" alt="red" width="8" height="8">'; } ?> </td> </tr> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028655 Share on other sites More sharing options...
True`Logic Posted March 19, 2010 Share Posted March 19, 2010 so you're trying to do something like this? <?php $testarr = {3, 5, 7, 10, 14}; $min = 4; $max 9; function Check($low, $high, $check) { if(($check >= $low) && ($check <= $high)) { return "img/bullet_green.png"; } else { return "img/bullet_red.png"; } } echo "<table border=1 cellspacing=0 cellpadding=1>\r\n"; for($i = 0; $i < count($testarr); $i++) { echo "<tr><td>$testarr[$i]</td><td><img src=\"" . Check($min, $max, $testarr[$i]) . "\" alt=\"\" width=\"8\" height=\"8\"></td></tr>\r\n"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028657 Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 All this code is so ridden with errors and disorganization. What are you exactly trying to accomplish with your code? I'm sure there is a much easier solution than the aformentioned ones. Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028660 Share on other sites More sharing options...
jacko_162 Posted March 19, 2010 Author Share Posted March 19, 2010 All this code is so ridden with errors and disorganization. What are you exactly trying to accomplish with your code? I'm sure there is a much easier solution than the aformentioned ones. its a little confusing but i shall give it a try; the initital code check if "test1" is in the array and if it is prints the html code for the 3x <td> table, within this table i need to show the Test name which i can input manually into the first <td> then the second <td> echos the $test1 result and the 3rd <td> is a piece of code that checks if the $test1 result is between 2 variables and echo a certain image if its between the 2x set values again entered manually. make sense? Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028814 Share on other sites More sharing options...
jacko_162 Posted March 20, 2010 Author Share Posted March 20, 2010 can anyone help me please? Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028893 Share on other sites More sharing options...
litebearer Posted March 20, 2010 Share Posted March 20, 2010 This handles check for the condition you desire and displays the proper image... <td> <?PHP if (($val3 > $val1) && ($val3 < $val2)) { echo '<img src="img/bullet_green.png" alt="green" width="8" height="8">'; }else{ echo '<img src="img/bullet_red.png" alt="red" width="8" height="8">'; } ?> </td> Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028906 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 <?php $val1 = 1.022; //----- Lowest Value $val2 = 1.027; //----- Highest Value $val3 = 1.026; //----- Test Value (change number accordingly) echo "<table>\n<tr><td>Value 1:</td><td>$val1</td></tr>\n<tr><td>Value 2:</td><td>$val2</td></tr> <tr><td>Value 3:</td><td>$val3</td></tr>\n<tr><td>Image:</td><td>"; if (($val3 > $val1) && ($val3 < $val2)) { echo '<img src="img/bullet_green.png" alt="" width="8" height="8" />'; }else{ echo '<img src="img/bullet_red.png" alt="" width="8" height="8" />'; } echo "</td></tr>\n</table>"; ?> Which will result in: <table> <tr><td>Value 1:</td><td>1.022</td></tr> <tr><td>Value 2:</td><td>1.027</td></tr> <tr><td>Value 3:</td><td>1.026</td></tr> <tr><td>Image:</td><td><img src="img/bullet_green.png" alt="" width="8" height="8" /></td></tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1028930 Share on other sites More sharing options...
jacko_162 Posted March 20, 2010 Author Share Posted March 20, 2010 guys your coding works but its not using the first code snippet i needed, which is to only display all the above coding if "test1" is in the array; <?php echo (in_array("test1",$arr) ? "<tr><td> </td><td> </td><td> </td></tr>" : ''); ?> Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029061 Share on other sites More sharing options...
litebearer Posted March 20, 2010 Share Posted March 20, 2010 if (in_array("test1", $array)) { ?> echo "<td>"; <?PHP if (($val3 > $val1) && ($val3 < $val2)) { echo '<img src="img/bullet_green.png" alt="green" width="8" height="8">'; }else{ echo '<img src="img/bullet_red.png" alt="red" width="8" height="8">'; } echo "</td> "; } Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029073 Share on other sites More sharing options...
jacko_162 Posted March 20, 2010 Author Share Posted March 20, 2010 thanks for help guys im nearly getting there. ok here is my code; <?php $val1 = 1.022; //----- Lowest Value $val2 = 1.027; //----- Highest Value $val3 = $test1; //----- Test Value (change number accordingly) if (in_array('test1',$arr)){ echo '<table width="100%"><tr>'; echo '<td><div align="right"><em><strong>Salinity:</strong></em></div></td>'; echo '<td>$val3</td>'; // ----- PROBLEM IS HERE if (($val3 > $val1) && ($val3 < $val2)) { echo '<td><img src="img/bullet_green.png" alt="" width="8" height="8" /></td>'; } else { echo '<td><img src="img/bullet_red.png" alt="" width="8" height="8" /></td>'; } echo '</tr></table>'; }else{ echo ''; } ?> its all working except its not echoing $val3 i marked on code where it is.. do i need a print command or wrap it in tags? Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029082 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 My friend. There is no problem You just haven't made a variable for $test1 Well to make it clearer you haven't defined it. Place $test1 = 1.026; someone above all the $val's There you go Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029085 Share on other sites More sharing options...
jacko_162 Posted March 20, 2010 Author Share Posted March 20, 2010 ruzzas, $test1 is defined above the php code with a load of other variables, it also doesnt print $val1 which is defined when i tested it. Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029087 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Oh i see the problem. The person who wrote the code up didn't realize that variables don't get printed in ' 's they need to be in quotes. <?php $val1 = 1.022; //----- Lowest Value $val2 = 1.027; //----- Highest Value $val3 = $test1; //----- Test Value (change number accordingly) if (in_array('test1',$arr)){ echo '<table width="100%"><tr>'; echo '<td><div align="right"><em><strong>Salinity:</strong></em></div></td>'; echo "<td>$val3</td>"; if (($val3 > $val1) && ($val3 < $val2)) { echo '<td><img src="img/bullet_green.png" alt="" width="8" height="8" /></td>'; } else { echo '<td><img src="img/bullet_red.png" alt="" width="8" height="8" /></td>'; } echo '</tr></table>'; }else{ echo ''; } ?> Try that Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029091 Share on other sites More sharing options...
jacko_162 Posted March 20, 2010 Author Share Posted March 20, 2010 worked a treat, it confuses me on when i need to use '' or quotes Quote Link to comment https://forums.phpfreaks.com/topic/195813-code-not-displaying-properly/#findComment-1029096 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.