TFD3 Posted July 28, 2007 Share Posted July 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 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> Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 out of all these people online no one can help me I cant learn if I dont get any help. I would help others with their questions but I dont know much about PHP yet Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 just create an array with the colours in it for each value...then echo back echo "<span style=\"" $color[$i]\">$compass[$i]</span"; or something similiar Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 I did just that but an getting this error: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/alabamaw/public_html/beta/dispatch/test.php on line 23 Ideas? Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted July 28, 2007 Share Posted July 28, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 $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 Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 I think he forgot the ? mark foreach ($compass as $possibility) { $sel = ($_POST['val'] == $possibility) ? 'selected="selected"' : ''; echo "<option value=\"". $possibility ."\" ". $sel .">". $possibility ."</option>\n"; } Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 $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. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 Umm the link you gave me is a restricted area so I have no idea what to see. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 Umm the link you gave me is a restricted area so I have no idea what to see. 4 got, sorry...try this one: http://www.alabamaweather.org/beta/testing/dispatch_test.php Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 $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"> Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 $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 Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 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 " Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 Im just setting here laughing now...its the only thing to do when you cant get something to work right http://www.alabamaweather.org/beta/testing/dispatch_test.php Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 You need to open the FILE "../test" and empty its contents. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 Read the last line http://www.alabamaweather.org/beta/testing/dispatch_test.php Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 lol no problem, just remember to press the topic solved button. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 28, 2007 Author Share Posted July 28, 2007 lol no problem, just remember to press the topic solved button. just did Quote Link to comment 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.