Jump to content

[SOLVED] MySQL/PHP help please


freelancer

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

 

 

 

Link to comment
Share on other sites

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 :P

 

NB! This login isn't anything, just made for test

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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.

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.