PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Fri Feb 11, 2005 7:16 pm
I have the following function that is supposed to change the color what is displayed; whether being win, tie, or loss. For some reason it is not displaying them correctly, havent figured out the pattern yet =\ - any ideas?
Code: Select all
function recentmatchresult()
{
$query = "SELECT final FROM matches ORDER BY id DESC LIMIT 0, 5";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
switch ($rowї'final'])
{
case "WIN":
echo '<font color="green">';
break;
case "TIE":
echo '<font color="blue">';
break;
case "LOSS":
echo '<font color="#990000">';
break;
}
$res .= "".$rowї'final']."<br>";
}
echo $res;
}
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Feb 11, 2005 7:24 pm
I can't see any problem with the function.... what happens when you use it? Where does $res get defined? Do you have a bigger slice of code?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 11, 2005 7:42 pm
your echo'ing the colors, yet concatenating the value you are coloring?
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Fri Feb 11, 2005 11:12 pm
on the admin side which i put it:
Code: Select all
<form action="insert.php" method="post" >
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td valign="middle"><h2>Date of Match</h2></td>
<td><input name="matchdate" type="text" maxlength="8"></td>
</tr>
<tr>
<td valign="middle"><h2>Oppopent</h2></td>
<td><input name="opponent" type="text" maxlength="25"></td>
</tr>
<tr>
<td valign="middle"><h2>League/Event</h2></td>
<td><input name="league" type="text" maxlength="25"></td>
</tr>
<tr>
<td valign="middle"><h2>Map</h2></td>
<td><input name="map" type="text" id="map" maxlength="25"></td>
</tr>
<tr>
<td valign="middle"><h2>Score</h2></td>
<td><input name="score" type="text" maxlength="5"></td>
</tr>
<tr>
<td valign="middle"><h2>Result</h2></td>
<td><select name="final" size="1" id="final">
<option class="win">WIN</font></option>
<option class="tie">TIE</option>
<option class="loss">LOSS</option>
</select></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td> <input type="Submit"></td>
</tr>
</table>
</form>
and then the insert page where it inserts in db
Code: Select all
<?
include("config.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO matches VALUES ('','$matchdate','$opponent','$league','$map','$score','$final');";
echo "Match Added: ";
$q = mysql_query($query) or die ("<font face=990000>Failed</font>");
echo "<font color=003366>Successful</font><br>";
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 11, 2005 11:18 pm
did you read and understand my post? .. I said what the problem is..
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Fri Feb 11, 2005 11:41 pm
did not understand it, sorry =\
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 11, 2005 11:47 pm
okay.. here's your originally posted code, which I added some comments to:
Code: Select all
function recentmatchresult()
{
$query = "SELECT final FROM matches ORDER BY id DESC LIMIT 0, 5";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
switch ($rowї'final'])
{
case "WIN":
echo '<font color="green">'; // <-- echo line
break;
case "TIE":
echo '<font color="blue">'; // <-- echo line
break;
case "LOSS":
echo '<font color="#990000">'; // <-- echo line
break;
}
$res .= "".$rowї'final']."<br>"; // <-- concat line
}
echo $res;
}
The first three commented lines are echo lines. They are echoing the font color out. The last commented line concatenates (joins together) the switched upon data only. The font coloring is sent elsewhere.
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Fri Feb 11, 2005 11:53 pm
Okay, so do away with the echo? I am a little confused and its late =\
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 11, 2005 11:59 pm
I believe you need to concat the font color with $res..
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Sat Feb 12, 2005 12:04 am
Sorry, am not used to this term, concat
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Feb 12, 2005 12:08 am
concat, short for concatenate ::
dictionary.com wrote: con·cat·e·nate
tr.v. con·cat·e·nat·ed, con·cat·e·nat·ing, con·cat·e·nates
1. To connect or link in a series or chain.
2. Computer Science. To arrange (strings of characters) into a chained list.
it's the dot (.) operator in php.
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Sat Feb 12, 2005 12:19 am
Okay....still dont understand what to do the
Code: Select all
$res .= "".$rowї'final']."<br>";
where do i concat?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Feb 12, 2005 12:22 am
you don't do anything to that line, only the first three lines I commented.
HuntHerr
Forum Newbie
Posts: 10 Joined: Mon Jun 30, 2003 10:17 pm
Post
by HuntHerr » Sat Feb 12, 2005 12:25 am
thanks