kat35601 Posted November 25, 2014 Share Posted November 25, 2014 I want to change the background to a light gray if the value of the $UOMPDROPSEQUENCE field is an odd number. What would be the best way to do this please keep in mind I am very new to programming and PHP Thanks Below is a snippet of my code. $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } echo "<table><tr>"; echo "<th>Drop</th>"; echo "<th>Name</th>"; echo "<th>Note</th>"; echo "<th>PO</th>"; echo "<th>Box_count</th>"; echo "<th>Cubes</th>"; echo "<th>ADDRESSLINE</th>"; echo "<th>ADDRESS2</th>"; echo "<th>CITY</th>"; echo "<th>STATE</th>"; echo "<th>ZIP</th>"; echo "<th>Order_ID</th>"; echo "<th> Phone </th>"; while (odbc_fetch_row($result)) { $UOMPDROPSEQUENCE=odbc_result($result,"UOMPDROPSEQUENCE"); $cmlName=odbc_result($result,"cmlName"); $UCMLSTOREHOURSTXT=odbc_result($result,"UCMLSTOREHOURSTXT"); $ompCustomerPO=odbc_result($result,"ompCustomerPO"); $UOMPTOTALBOXCOUNT=odbc_result($result,"UOMPTOTALBOXCOUNT"); $UOMPVOLUMETOTAL=odbc_result($result,"UOMPVOLUMETOTAL"); $CMLADDRESSLINE1=odbc_result($result,"CMLADDRESSLINE1"); $CMLADDRESSLINE2=odbc_result($result,"CMLADDRESSLINE2"); $CMLCITY=odbc_result($result,"CMLCITY"); $CMLSTATE=odbc_result($result,"CMLSTATE"); $CMLPOSTCODE=odbc_result($result,"CMLPOSTCODE"); $ompSalesOrderID=odbc_result($result,"ompSalesOrderID"); $cmlPhoneNumber=odbc_result($result,"cmlPhoneNumber"); echo "<tr><td>$UOMPDROPSEQUENCE </td>"; echo "<td align='center'>$cmlPhoneNumber</td>"; echo "<td align='center'>$UCMLSTOREHOURSTXT</td>"; echo "<td align='center'>$ompCustomerPO</td>"; echo "<td align='center'>$UOMPTOTALBOXCOUNT</td>"; echo "<td align='center'>$UOMPVOLUMETOTAL</td>"; echo "<td align='center'>$CMLADDRESSLINE1</td>"; echo "<td align='center'>$CMLADDRESSLINE2</td>"; echo "<td align='center'>$CMLCITY</td>"; echo "<td align='center'>$CMLSTATE</td>"; echo "<td align='center'>$CMLPOSTCODE</td>"; echo "<td align='center'>$ompSalesOrderID</td>"; echo "<td align='center'> $cmlPhoneNumber</td></tr>"; } odbc_close($connect); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 25, 2014 Share Posted November 25, 2014 Well, you do have some errors in your code, but the usual solution would be to set the row's background color. Add this to your tr tag <tr class='$bkgrnd'> Then in your style section of your html code add two classes: .color1 {background-color:white;} .color2 {background-color:lightgray;} In your loop now check the value of your data and set $bkgrnd to either 'color1' or 'color2' depending upon what you want. Note: you are missing the closing row tag on your headings. Also - you should look at the odbc_fetch_array function instead of using the odbc_result one that you are using. Your method is very resource intensive (ie, inefficient). Using the fetch_array function will get all your values in an array and you can use those elements in your output loop. Check the manual for examples. Quote Link to comment Share on other sites More sharing options...
Solution kat35601 Posted November 26, 2014 Author Solution Share Posted November 26, 2014 This is how I colored the background of my rows based on odd or even. Not sure if it is the right way but it works great. { { if($UOMPDROPSEQUENCE % 2 == 0 ) {$style = '#ffa500';} else {$style = '#fffafa';}} // Then echo "<tr bgcolor=$style><th>$UOMPDROPSEQUENCE</th>"; Quote Link to comment Share on other sites More sharing options...
CroNiX Posted November 26, 2014 Share Posted November 26, 2014 This can be done purely with CSS and no other coding. http://www.w3.org/Style/Examples/007/evenodd.en.html 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.