Jump to content

code not displaying properly...


jacko_162

Recommended Posts

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?

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

<?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>

Link to comment
Share on other sites

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>" : '');
?>

Link to comment
Share on other sites

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>    ";
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.