Jump to content

[SOLVED] $compass array help


TFD3

Recommended Posts

In this script:

 

<?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($_POST["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?>

 

When I go to select the possible choices which would be ("Center Point","Birmingham","Trussville","Fultondale") I would like them to show up in different colors depending on which I choose. However i dont know where to start.

If someone could help me that would be great as im a noob to this stuff.

 

Thanks,

Kenny

Link to comment
Share on other sites

Here is the WHOLE script that includes what I have typed in the post above this:

Like I said if I choose Center Point then I want it to show up in a certain color and if I chose Birmingham have it show up in another color. But dont know how to do this.

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs - <a href=" hidden "><font color="#CCCCCC" size="2">Refresh</a></font>
</H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
  <?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($_POST["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($_POST["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="Submit">
<input type="Reset" value="Clear" name="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($_POST['Submit'])){
    $fh = fopen("../test","a");
    fputs($fh,
    $_POST["one"]." | ".
    $_POST["two"]." | ".
    $_POST["three"]." | ".
    $_POST["four"]." | ".
    $_POST["five"]." | ".
    $_POST["six"]."".
    "\n");
fclose($fh);
}
?>

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
// Echo the file contents onto the end of the form
$stuff = implode("",file("../test"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>

</body>
</html>

Link to comment
Share on other sites

umm that was sloppy coding on my part

foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo (" selected");
     echo ">$possibility";
  }

but you will have to make some modifications to your needs.

Link to comment
Share on other sites

also, i dont think you're outputting valid html

 

try

 

foreach ($compass as $possibility) {

$sel = ($_POST['val'] == $possibility) 'selected="selected"' : '';

echo "<option value=\"". $possibility ."\" ". $sel .">". $possibility ."</option>\n";

}

Link to comment
Share on other sites

$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo ">" . $possibility . "</option>\n";
     $i++;
  }

 

maybe something like that

Link to comment
Share on other sites

also, i dont think you're outputting valid html

 

try

 

foreach ($compass as $possibility) {

$sel = ($_POST['val'] == $possibility) 'selected="selected"' : '';

echo "<option value=\"". $possibility ."\" ". $sel .">". $possibility ."</option>\n";

}

 

Using that gives me:

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

Link to comment
Share on other sites

$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo ">" . $possibility . "</option>\n";
     $i++;
  }

 

maybe something like that

 

Load this webpage:

http://www.alabamaweather.org/beta/dispatch/test.php

Now click the drop down arrow. Using the script you listed above made the choices in the drop down arrow colored in the background.

Go ahead and hit the submit button and you will see that the department choice is still white.

Its the department text in the output that needs to be a set color.

Link to comment
Share on other sites

I think he forgot the ? mark

 

foreach ($compass as $possibility) {
$sel = ($_POST['val'] == $possibility) ? 'selected="selected"' : '';
echo "<option value=\"". $possibility ."\" ". $sel .">". $possibility ."</option>\n";
}

 

Im not as much worried about the valid html right now as I am for the department colors.

Link to comment
Share on other sites

$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\" value=\"<span style=\"color: " . $color[$i] . "\">" . $possibility . "</span>\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo ">" . $possibility . "</option>\n";
     $i++;
  }

 

something like that, so when you load the file they'll be colored, provided you remove the <FONT style="BACKGROUND-COLOR: #808080">

Link to comment
Share on other sites

$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\" value=\"<span style=\"color: " . $color[$i] . "\">" . $possibility . "</span>\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo ">" . $possibility . "</option>\n";
     $i++;
  }

 

something like that, so when you load the file they'll be colored, provided you remove the <FONT style="BACKGROUND-COLOR: #808080">

 

unfortunately, that does not work...

http://www.alabamaweather.org/beta/testing/dispatch_test.php

Link to comment
Share on other sites

rather use

 

$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo "value=\"" . $possibility . ":" . $color[$i] . ":>" . $possibility . "</option>\n";
     $i++;
  }

 

and for the file printing

 

replace echo (nl2br(htmlspecialchars(stripslashes($stuff))));

 

with

$value = explode("\n",$stuff);
$count = count($value);
for($i=0;$i<$count;$i++){
$b = stripslashes(htmlspecialchars(explode(":",$value[$i])));
print "<span style=\"color: " . $b[1] . "\">" . $b[0] . "</span>" . $b[2];
}

 

 

removed an extra "

Link to comment
Share on other sites

Ok I think i have the script properly re-written. Ill just add it at the end of this post.

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs - <a href=" hidden "><font color="#CCCCCC" size="2">Refresh</a></font>
</H1>
<?php
// This is a form with "sticky" fields .....
?>
<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
<?php
$compass = array("Center Point","Birmingham","Trussville","Fultondale") ;
$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo " value=\"" . $possibility . "^" . $color[$i] . "^\">" . $possibility . "</option>\n";
     $i++;
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($_POST["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="Submit">
<input type="Reset" value="Clear" name="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($_POST['Submit'])){
    $fh = fopen("../test","a");
    fputs($fh,
    $_POST["one"]." | ".
    $_POST["two"]." | ".
    $_POST["three"]." | ".
    $_POST["four"]." | ".
    $_POST["five"]." | ".
    $_POST["six"]."".
    "\n");
fclose($fh);
}
// Echo the file contents onto the end of the form
$stuff = implode("",file("../test"));
$value = explode("\n",$stuff);
$count = count($value);
for($i=0;$i<$count;$i++){
$b = explode("^",$value[$i]);
$b[0] = stripslashes(htmlspecialchars($b[0]));
$b[1] = stripslashes(htmlspecialchars($b[1]));
$b[2] = stripslashes(htmlspecialchars($b[2]));
print "<span style=\"color: " . $b[1] . "\">" . $b[0] . "</span>" . $b[2] ."<br>";
}
?>
</body>
</html>

 

I was busy earlier but I managed to make up some sort of solution.

 

All you have to do to change colours is view a hex chart like this

 

http://www.draac.com/hexchart.html

 

and modify the values in the $color array accordingly.

 

Link to comment
Share on other sites

Ok I think i have the script properly re-written. Ill just add it at the end of this post.

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs - <a href=" hidden "><font color="#CCCCCC" size="2">Refresh</a></font>
</H1>
<?php
// This is a form with "sticky" fields .....
?>
<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
<?php
$compass = array("Center Point","Birmingham","Trussville","Fultondale") ;
$color = array(0=>"#BBBBBB",1=>"#CCCCCC",2=>"#FFFFFF",3=>"#EEEEEE");
$i = 0;
foreach ($compass as $possibility) {
     echo "<option style=\"background-color: " . $color[$i] . "\"";
     if ($_POST["one"] == $possibility) echo "selected=\"selected\"";
     echo " value=\"" . $possibility . "^" . $color[$i] . "^\">" . $possibility . "</option>\n";
     $i++;
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($_POST["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($_POST["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="Submit">
<input type="Reset" value="Clear" name="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($_POST['Submit'])){
    $fh = fopen("../test","a");
    fputs($fh,
    $_POST["one"]." | ".
    $_POST["two"]." | ".
    $_POST["three"]." | ".
    $_POST["four"]." | ".
    $_POST["five"]." | ".
    $_POST["six"]."".
    "\n");
fclose($fh);
}
// Echo the file contents onto the end of the form
$stuff = implode("",file("../test"));
$value = explode("\n",$stuff);
$count = count($value);
for($i=0;$i<$count;$i++){
$b = explode("^",$value[$i]);
$b[0] = stripslashes(htmlspecialchars($b[0]));
$b[1] = stripslashes(htmlspecialchars($b[1]));
$b[2] = stripslashes(htmlspecialchars($b[2]));
print "<span style=\"color: " . $b[1] . "\">" . $b[0] . "</span>" . $b[2] ."<br>";
}
?>
</body>
</html>

 

I was busy earlier but I managed to make up some sort of solution.

 

All you have to do to change colours is view a hex chart like this

 

http://www.draac.com/hexchart.html

 

and modify the values in the $color array accordingly.

 

 

It works...but other things are showing up???

http://www.alabamaweather.org/beta/testing/dispatch_test.php

 

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.