Forum Moderators: coopster
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>
.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.
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.
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.