Forum Moderators: coopster

Message Too Old, No Replies

having trouble changing row colors

         

disco2424

9:26 pm on Jun 18, 2008 (gmt 0)

10+ Year Member



Hello,

Please forgive me if this is the wrong spot to be posting this as I’m very new to this site and to PHP.

To explain what I’m doing.
I've created a HTML page to enter in tracking information which is sent to my database (MYSQL). Everything is working when it comes to entering data and the populating the database. The Problem I'm having is with my results script (php). I would like to be able to change the color of each row depending on it's value.

When I enter in a Returns (value=1) or a Shipped (value=2) these values are placed in the $category column or the database. I'm not sure how to edit my script to be able to change each row depending on the value selected.

Here is my php I have already.

Any help would be much appreciated.

<body>

<center>

<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="20"><b>id</b></td>
<td width="150"><b>Name</b></td>
<td width="20"><b>Lane ID</b></td>
<td width="100"><b>Mac address</b></td>
<td width="300"><b>Problem reported</b></td>
<td width="300"><b>Our findings</b></td>
<td width="40"><b>Staff Helping</b></td>
<td width="75"><b>Date</b></td>
<td width="75"><b>Action Taken</b></td>
</tr>
<tr>
<td>
<? $hostname = "localhost"; // The DB server.
$username = "*"; // The username you created for this database.
$password = "*"; // The password you created for the username.
$usertable = "*"; // The name of the table.
$dbName = "*"; // This is the name of the database.

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)begins
$XX = "No Record Found, to search again please click either back or search again";
$metode=$_POST["metode"];
$search=$_POST["search"];

//query details table begins
$query = mysql_query("SELECT * FROM LivePro WHERE $metode LIKE '%$search%'");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["id"];
$variable2=$row["name"];
$variable3=$row["lane_id"];
$variable4=$row["mac_address"];
$variable5=$row["problem_reported"];
$variable6=$row["our_findings"];
$variable7=$row["staff_helping"];
$variable8=$row["date"];
$variable9=$row["action_taken"];

//table layout for results

print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("<td>$variable6</td>");
print ("<td>$variable7</td>");
print ("<td>$variable8</td>");
print ("<td>$variable9</td>");
print ("</tr>");
}
//below this is the function for no record!
if (!$variable1)
{
print ("$XX");
}
//end
?>
</table>
</center>

<br />
<center>
<a href="index.html" target="_self">Insert another record</a>
</center>

<br />
<center>
<a href="search.html" target="_self">Search another record</a>
</center>

</body>

deMorte

10:45 am on Jun 19, 2008 (gmt 0)

10+ Year Member



I'm not sure if I understood the question correctly, but here's my input.
You could do two CSS-classes that would have the background color of your liking, example:
.color1{ background-color:#FF0000; } 
.color2{ background-color:#0000FF; }
Then just use out to these classes when you are printing the results. Example:
print("<td class=color$category>$variable1</td>");
This would change the background color to red and blue depending on the $category variable.

Hope this helps. If not, maybe you can illustrate your problem further.

disco2424

3:03 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



Thank you for your reply. I will try to explain it a littel better.
I have a results.php file that gets its data from the the database and prints it to the search.html.

everything else is working the only difference I want to make is when you do a search each row on that page will have a different background color depending on what was entered. It can be two opitons that are entered either Returned (value=1) or shipped (value=2). I just want it to be easier for somebody to look at and be able to see which are returns and which are shipped items. They should see multiple colors when its working. For example Returns can be blue and shipped can be red.

I hope this explains it a little better.

Thank you again for you post.

cameraman

4:13 pm on Jun 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, disco2424.
deMorte's solution is the same way I'd do it.

Apply it here:
//table layout for results

print ("<tr class=\"color" . $value . "\">");
print ("<td>$variable1</td>");
.
.

I'm unclear as to what variable you're monitoring for value=1 or value=2, so substitute the variable name for $value above.

disco2424

5:27 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



thanks to both of you guys for your replies. I just figured it out then noticed cameraman's post.

This is what I did and all is woking.

$variable10=$row["category"];
$variable11=($variable10==1) ? '#CCCCCC' : '#0099FF';

print ("<tr bgcolor=$variable11>");

Again thanks for all the help.