freelancer Posted February 11, 2007 Share Posted February 11, 2007 I'd like to add my page dropdown menu for example in my script where I can add matches there will be dropdown menu witch includes 3 choices: 'Win, Lost, Tide' and when I choose 'Win' - text color turns Green, 'Lost' - turns red and 'Tide' - turns Yellow. My adding script is based on sql that you can add fields to my table and on my page all tables are included. I hope you understand what I mean. Thank you Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 You will need to be alot clearer in your description, posting some relevent code might also help. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 This is my code on page where tables are included <?php include("config.php"); mysql_connect("server", $username, $password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM results"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="0" cellpadding="2" class="results" width="404"> <tr align="left"> <th width="120">Opponent</th> <th width="97">Map</th> <th width="74">Score</th> <th width="98">Type</th> </tr> <? $i=0; while ($i < $num) { $opponent=mysql_result($result,$i,"opponent"); $map=mysql_result($result,$i,"map"); $score=mysql_result($result,$i,"score"); $type=mysql_result($result,$i,"type"); ?> <tr align="left"> <td><? echo $opponent ?></td> <td><? echo $map; ?></td> <td><? echo $score; ?></td> <td><? echo $type; ?></td> </tr> <? $i++; } echo "</table>"; ?> Now I want that if I add my results from this script and I choose some of these choices then $score turns to specific color <form action="insert.php" method="post"> Opponent: <br><input type="text" name="opponent"><br> Map: <br><input type="text" name="map"><br> Score: <br><input type="text" name="score"><br> Type: <br><input type="text" name="type"><br> Result:<br> <select size="1" name="res"> <option>Win</option> <option>Lost</option> <option>Tide</option> </select><br> <input type="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Sorry... I dont see any variable called $score. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Well, I mean that in my page where table 'results' is included, number below created table for example: 10-0, 0-2 ect. will be colored. I made mad paintskills drawing witch should explain. If you choose Win from dropdown, then on web (upper one is web witch is seperated with blackline and below is results adding panel witch one is protected with password) score number will changes. http://www.team-kommando.com/paint.JPG Quote Link to comment Share on other sites More sharing options...
giba Posted February 11, 2007 Share Posted February 11, 2007 If your problem is about coloring you check box try using Style Sheet: So: put into head section <head> <style type="text/css"> <!-- .red {color: #FF0000} .green {color: #009933; } .blue {color: #0000FF; } --> </style> </head> Then match this by 'class' atribute in the check box: <option class="green">Win</option> <option class="red">Lost</option> <option class="blue">Tide</option> You will have it! Now, if you want something else! Sorry! Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 No sorry, I didn't mean that. Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Place giba's css in the head of your doc, then replace this.... <td><? echo $score; ?></td> with.... <?php swithc($_POST['res']) { case 'Win' : echo '<td class="green">$score;</td>'; break; case 'Lost' : echo '<td class="red">$score;</td>'; break; case 'Tide' : echo '<td class="blue">$score;</td>'; break; } ?> Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Well, I worked out this method that now I can put<font color="red"></font> around my score field but I would like to know that is it possible to make it so, when I choose or click any of colors from dropdown then it covers this word what is inside field with <font color="w/e"></font> so I don't have to write it myself always. Should be same as choosing bold, code, email ect.. in this forum, that it puts these around it. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Make it a class, such as winner. do <span class="winner">Winner</span> and in your CSS file, specify the color. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Make it a class, such as winner. do <span class="winner">Winner</span> and in your CSS file, specify the color. Can you please be more specific, I can't get where I should add it correctly and how does it help exactly. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Oh if you use thorpe's way, he used classes. He misspelled switch, so fix that, and use his. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Yes I saw already that he misspelled, but I can't get how to use it at this problem :/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 "If you choose Win from dropdown, then on web (upper one is web witch is seperated with blackline and below is results adding panel witch one is protected with password) score number will changes." Are you saying you want it to change right then, before you hit any buttons? That's done with javascript. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 11, 2007 Share Posted February 11, 2007 In the head of your HTML file: <html> <head> <title>My HTML page</title> <link rel="stylesheet" type="text/css" href="main_area.css" /> </head> Now make a plain text file called "main_area.css" .winner {color: #ff0000} .loser {color: #ffff00} Now the line of HTML in your script to change the color: <span class="winner">Winner</span> That's all there is to it. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Yes, accutaly I meant later that if you click/choose any of WIN/LOST/TIDE from menu then it changes it before submiting. Knew it was javascript, but how to render it there? Thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 11, 2007 Share Posted February 11, 2007 Ah now js isn't really a strong point of mine, I try and avoid using it where I can Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Then this belongs on the javascript forum! Check out mootools, it has a great library of js effects. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 11, 2007 Author Share Posted February 11, 2007 Well I'm not strong at PHP also, but I don't know also witch is the easiest way to do it, you all may help ;P Quote Link to comment Share on other sites More sharing options...
giba Posted February 12, 2007 Share Posted February 12, 2007 Do you have and algorithm? Let us understand! You have a database where you stored the results. Then your table displays the result differenciating by a position's color, in you case: 'Win' = 'green' 'Lost' = 'red' 'Tide' = 'Yellow' (I recommend blue), but the big deal is: the result must vary constantly, because a game is so. Then when you submit the form (the critic one) a search is done and the ones who are in winner position will be displayed in green, but when loosing position this must change the color. you'll have to work with comparisons I think, and redo your application in some aspects. The value stored in you database must be compared by some value ($variable by $variable). An example: Four guys Playing a game: $player1_score=3 $player2_score=5 $player3_score=1 $player4_score=7 In this situation we have player 4 as winner, player 1 and 3 tide, and player 2 lost position. Well for $player versus $player you'll must compare them when displaying results, or you must have a algorithm to calculate who's on top. Later, you only apply the cascade in output to color it. The problem I guess is about the algorithm of your application. I mean you must create some logic for that! Then implement! No confusion just sugestion! Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 12, 2007 Author Share Posted February 12, 2007 Oh well, I try to explain it all again to you, maybe I get solution At my webpage's results page (http://www.team-kommando.com/?k=results ) is place where database table is inserted. When I add results from my mini admin panel (http://www.team-kommando.com/web/addresults.php "password: test") and I put to score field whatever number, let say 10-0 and from dropdown menu I choose WIN, then to database it will be stored like <font color="green">number</font> or by style class. How should this be in practice. Here are my codes: addresults.php <?php include("config.php"); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM results"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $parool = "test"; if($logi1 == $parool) { ?> <p><font face="Tahoma" size="2">Add result</font></p><br> <form action="insert.php" method="post"> Opponent: <br><input type="text" name="opponent"><br> Map: <br><input type="text" name="map"><br> Score: <br><input type="text" name="score"> <select name="res"> <option>Win</option> <option>Lost</option> <option>Tide</option> </select><br> Type: <br><input type="text" name="type"><br> <input type="Submit" value="Add"> </form><br> <p><font face="Tahoma" size="2">Delete</font></p> <? include("delete.php"); ?> <?php exit; } ?> insert.php <? include("config.php"); $opponent=$_POST['opponent']; $map=$_POST['map']; $score=$_POST['score']; $type=$_POST['type']; @mysql_select_db($database) or die( "No database to select!"); $query = "INSERT INTO results VALUES ('','$opponent','$map','$score','$type')"; if (empty($opponent)) { echo 'Ehe, no '; } else mysql_query($query); mysql_close(); ?> Output @ webpage <?php include("config.php"); @mysql_select_db($database) or die( "No database to select!"); $query="SELECT * FROM results"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="0" cellpadding="2" class="results" width="404"> <tr align="left"> <th width="120">Opponent</th> <th width="97">Map</th> <th width="74">Score</th> <th width="98">Type</th> </tr> <? $i=0; while ($i < $num) { $opponent=mysql_result($result,$i,"opponent"); $map=mysql_result($result,$i,"map"); $score=mysql_result($result,$i,"score"); $type=mysql_result($result,$i,"type"); ?> <tr align="left"> <td><? echo $opponent ?></td> <td><? echo $map; ?></td> <td><? echo $score; ?></td> <td><? echo $type; ?></td> </tr> <? $i++; } echo "</table>"; ?> Please notice that I just created selection under addresults.php because I'm not sure how to exert it. Thank you, hopefully it helped NB! This login isn't anything, just made for test Quote Link to comment Share on other sites More sharing options...
giba Posted February 13, 2007 Share Posted February 13, 2007 Hi , I didn't even played today. Ehe! I solved that: (look at the red lines) <?php $i=0; while ($i < $num) { $res=mysql_result( $result,$i,"res"); $opponent=mysql_result($result,$i,"opponent"); $map=mysql_result($result,$i,"map"); $score=mysql_result($result,$i,"score"); $type=mysql_result($result,$i,"type"); // Color variables if ($res=="win") { $status="#FF0000"; } else if ($res=="lost") { $status="#008000"; } else { $status="#FFFF00"; } echo "<tr align=\"left\">"; echo "<td><font color=\"$status\">$opponent</font></td>"; echo "<td><font color=\"$status\">$map</font></td>"; echo "<td><font color=\"$status\">$score</font></td>"; echo "<td><font color=\"$status\">$type</font></td>"; echo "</tr>"; $i++; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
giba Posted February 13, 2007 Share Posted February 13, 2007 See your select. It must send the value to $res! Quote Link to comment Share on other sites More sharing options...
giba Posted February 13, 2007 Share Posted February 13, 2007 Add this to insert.php: (see the red lines and compare) (DON'T FORGET TO CREATE A NEW FIELD TO YOUR DATABASE!) $res=$_POST['res']; $opponent=$_POST['opponent']; $map=$_POST['map']; $score=$_POST['score']; $type=$_POST['type']; @mysql_select_db($database) or die( "No database to select!"); $query = "INSERT INTO results VALUES ('$opponent','$map','$score','$type','$res')"; if (empty($opponent)) { echo 'Ehe, no '; } else mysql_query($query); mysql_close(); Quote Link to comment Share on other sites More sharing options...
giba Posted February 13, 2007 Share Posted February 13, 2007 I didn't even play today- oh, yes! Good purpose!" $res must be obrigatory at the end of the insert query if you want just one of the columns to be displayed take away <font color=\"$status\"> and </font> from the others you don't. 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.