PHP - Background Color Depending On Variable
how can i set the color of a table background depending on what a variable is in my database?
I currently have a table which echos data from my database, but i want the background too be a color depending on the value of a variable called 'status' (there are 3 variations) the variations are; order placed, processing and complete so for example: Code: [Select] if (status == placed) { background would be red } Code: [Select] if (status == processing) { background would be orange } Code: [Select] if (status == complete) { background would be green } appreciate any help. thank you. Similar Tutorialsi have a small search profile search and need to set $getuname variable to users username if((trim($country) !== ''&&($state) !== ''&&($city) !== '')){ $data = mysql_query("SELECT * FROM users WHERE users.state='$state' AND users.country='$Country' AND users.city='$city' ORDER BY RAND() DESC LIMIT 1 "); Echo "Country city state search"; $getuname = mysql_real_escape_string($_GET['username']); am i meant to use the get or is that only for forms? I have to radio buttons at the login page. Both of them are in group1. The value of the first is 'fancy', the value of the second is 'fast'. Also note that the buttons are on the login page, and i want to change the bg on the main page. 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); I need a button in php to change my background color every 5 presses with a random one, every five presses the color have to change once and need to stay for the next 5 presses. here is my code <head>
<title>click 5 times</title> Hi, I've making a script that's almost a todo list, and i want to have 3 colors to the posts. Post under 7 days old should be green, and thoose older then 7 days yellow and over 14 days should be red. How could i do that? Every post i timestamp when stored in my MYSQL table. Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } $result = mysql_query("SELECT * FROM henvendelser ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr> <td>"; echo $row['id']; echo "</td> <td>"; echo date("d.m.y", strtotime($row["date"])); echo "</td> <td>"; echo "<a href=\"detaljer.php?view=$row[id]\">$row[Navn]</a>"; echo "</td> <td>"; echo $row['Telefon']; echo "</td> <td>"; echo $row['Emne']; echo "</td> </tr>"; } echo "</table>"; ?> Good Day, I am trying to create a table where the background color alternates between colors based on the category. The query sorts the category in alphabetical order. So for every category that is the same the background color will be the same. When the category changes, the background color changes. Alternating between two colors will be fine. I am not even sure where to begin on the sort of loop. So I want php to create a table like below: <table width="300" border="1" cellspacing="0" cellpadding="0"> <tr bgcolor="#CCCCCC"> <td width="117">Category 1</td> <td width="177">Excetion data</td> </tr> <tr bgcolor="#CCCCCC"> <td>Category 1</td> <td>Excetion data</td> </tr> <tr bgcolor="#CCCCCC"> <td>Category 1</td> <td>Excetion data</td> </tr> <tr bgcolor="#FFFFCC"> <td>Category 2</td> <td>Excetion data</td> </tr> <tr bgcolor="#FFFFCC"> <td>Category 2</td> <td>Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Category 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Category 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Categor 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> </table> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=352099.0 I was trying to show different hex codes as background in a loop for each section of a list. Here's what I done Code: [Select] $rgb; $rgb["c1"] = "ff4c54"; $rgb["c2"] = "ff764c"; $rgb["c3"] = "ffde4c"; $rgb["c3"] = "c7f25f"; $rgb["c4"] = "33c9f7"; $i=0; $pargs = array( 'numberposts' => 10,'orderby'=> 'comment_count', ); $myposts = get_posts( $pargs );$max_count=0; <ul> foreach( $myposts as $post ) : setup_postdata($post); <li style="width:300px;background-color:#<?php foreach($rgb as $color => $hex) { echo $hex[i]; $i++; } ?>"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - </li> <?php endforeach; ?> </ul> Ending up with just the white background.. and no change in the background colors. Kindly help This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317921.0 Hi, I have looked everywhere for a way to do this and would be grateful for a pointer in the right direction. I want to change the background color of the div with the id of "loggedin", depending on the status. The status currently echos text depending on the value. Code: [Select] <div class="grid_12" id="loggedin"> <div> <ul id="loggedin"> <li><?php global $current_user; get_currentuserinfo(); echo 'Status : ' . $current_user->status . "\n";?></li> <li> <?php if ($current_user->status=="RED") echo "Red info"; ?> <?php if ($current_user->status=="GREEN") echo "Green info"; ?> <?php if ($current_user->status=="BLUE") echo "Blue info"; ?> <?php if ($current_user->status=="YELLOW") echo "Yellow info"; ?> </li> </div> </div> Thanks Is there a way to query some information depending on if a table field DOES NOT include a specific value? I've got a table that contains over 100 locations. I want to organize the data on the frontend by country (specifically US and International). How would I go about filtering out locations that DO NOT belong in USA? $q = "SELECT * FROM table WHERE COUNTRY='USA'"; Alright, so meanwhile i wait for answer on the other thread i started another project, to fix the menu... but it was a bit confusing so now i ask you again!... Heres my current menu.php Code: [Select] <?php include "config.php"; if (!$_SESSION["valid_user"]) { echo '<a href="login.php">' . 'Login <br/><br/>' . '</a>'; } if ($_SESSION["valid_user"]) { echo '<a href="logout.php">' . 'Logout <br/><br/>' . '</a>'; echo '<a href="members.php">' . 'Control Panel <br/><br/>' . '</a>'; } echo '<a href="memberlist.php">' . 'Members <br/><br/>' . '</a>'; echo '<a href="ranking.php">' . 'Rankings <br/><br/>' . '</a>'; ?> Now it works perfectly when logged in, but when you logout the session dies, leaving me with this: Notice: Undefined index: valid_user in C:\wamp\www\kawaii\menu.php on line 5 Login Notice: Undefined index: valid_user in C:\wamp\www\kawaii\menu.php on line 10 Members Rankings Now, how can i make a login that depends on if your logged in if this happens when you logout..., i hope someone can find a solution that can work out Hi all, I am trying to produce a script that will send out an email but the user can basically choose how often they get this email... I want to give them the option of daily, weekly and monthly. I have the logic down on paper and in plain English it seems to make sense but I am having a hard time converting this to code: My logic is: 1. find out how often they want to get the email (we will call this frequency, as thats what my database field is called) 2. drag out last updated timestamp (this is called last_updated and is a unix timestamp) 3. some form of compare i.e. if frequency is weekly and $today is 7 days after last reminded alert them as I say this makes sense in plain English but I'm having a hard time converting it... this is what I have come up with so far: Code: [Select] <?php // Connect include("../connect.php"); $query = "SELECT * FROM resumes_bak WHERE jobseekerid = '2610'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $current_timestamp = time(); echo "Current Timestamp: ".$current_timestamp; echo "<br /><br />"; $frequency = $row['frequency']; echo "Frequency is: ".$frequency; echo "<br /><br />"; $lastReminded = $row['last_reminded']; echo "Last reminded: ".$lastReminded; echo "<br /><br />"; $daily = strtotime('+1 day', $lastReminded); echo "One day forward: ".$daily; echo "<br />"; $weekly = strtotime('+1 week', $lastReminded); echo "One week forward: ".$weekly; echo "<br />"; $monthly = strtotime('+1 month', $lastReminded); echo "One month forward: ".$monthly; echo "<br /><br />"; if($frequency = 'daily' && /* I THINK I NEED ADDITIONAL CLAUSES IN HERE TO DO THE COMPARISON */ ) { echo "I am daily"; } elseif ($frequency = 'weekly') { echo "I am weekly"; } else { echo "I am monthly"; } } ?> Can anybody help me on my way here, I seem to have hit a wall! Many thanks, Greens85 just a little confused where ( brackets go in this statement . im just wanting to to display the information differently depending on which message is returned from the database. thanks Code: [Select] if ($info['message'])="<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>";{ Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message']; }elseif ($info['message'])="You have sent a contact request to"; Echo " .$info['message']<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']."; } } Hi guys! How do I display different code depending on the title/url? This is the code for the form that brings you from "http://www.xxx.uk/index.php" to "http://www.xxx.uk/index.php?name=ro": Code: [Select] <form name="input" action="http://www.xxx.uk/index.php?name=ro" method="post"> Enter student number:<input type="text" name="sid"/> <input type="submit" value="Submit"> Now when you are on "http://www.xxx.uk/index.php?name=ro" I would like another content(but written in the same php file). I tried with _GET, but the problem is that I don't simply want to add a word but a lot of content. With _GET, that whole content would have to be displayed in the title and I don't want that. Hello. I recently posted about getting my top nav to work which it does now (with thanks) but im having trouble getting my side navs to work. i have tried various things but i think its just a case of getting the where clause right. see what you think. any help would be great these are my files. includes/navL1.php - which does the top navigation includes/navL2.php - which does the left navigation main includes/navL3.php - which does the left navigation sub admin/layouts/admin_topnav.php admin/layouts/admin_leftnav.php admin/layouts/index.php ok so. admin topnav.php code looks like this and works Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> now i need when a top nav is selected i need the correct left nav main and subs to show. this is how my left nav looks at the moment Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> SOME ACCORDION SCRIPT GOES HERE <div class="arrowlistmenu"> <?PHP $nav1 = navL1::find_all(); $nav2 = navL2::find_by_nav(); $nav2 = navL2::find_by_nav(); ?> <?PHP foreach($nav2 as $nav2s): ?><h3 class="menuheader expandable"> // MAIN LEVEL <li><a <?PHP echo ($pageName == $nav2s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav2s->title; ?>.php" id="<?PHP echo $nav2s->title; ?>"><?PHP echo $nav2s->title; ?></a></li></h3> <?PHP endforeach; ?> // SUB LEVEL <ul class="categoryitems"> <?PHP foreach($nav3 as $nav3s): ?> <li><a <?PHP echo ($pageName == $nav3s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav3s->title; ?>.php" id="<?PHP echo $nav3s->title; ?>"><?PHP echo $nav3s->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #End arrowlistmenu --> <img src="images/wrapper/loading.gif" alt="loading..." id="Pageloading" height="28" width="28" style="visibility:hidden;float:left;" /> this is the code im trying to get to work in my includes files that i can seem to get my head around includes/navL2.php Code: [Select] public static function find_by_nav(){ global $database; global $topNav; $sql = "SELECT * FROM ".self::$table_name." WHERE title="$topNav" LIMIT 1"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } the find_by_sql($sql) looks like this but i dont think you need it Code: [Select] public static function find_by_sql($sql){ global $database; $results_set = $database->query($sql); $object_array = array(); while($row = $database->fetch_array($results_set)){ $object_array[] = self::instantiate($row); } return $object_array; } im trying to use the same code to pull the sub levels inside includes/navL3.php if any of this makes sense please could you point out whats wrong thanks ricky Hey im having troube making this code as i have no idea how to do it... basically what im trying to do is for example if the index.php?id=XXX i want to echo "this" and if it is just index.php i want to echo "that" your help would be nice thanks <?php $id_lang = $_GET['id']; if($id_lang == $id_lang){ $result = mysql_query("SELECT * FROM pages WHERE id='$id_lang' ",$connect); while($row44 = mysql_fetch_assoc($result)) { $js_langdir = $row44['lang_dir']; }} else{ $js_langdir = "LTR"; } ?> Hi. Im pretty sure this is easy but ive been trying for hours and looked all over the web but cant seem to do it. I have information submitted to my database which I then retrieve on another page. I retrieve the landlord name and group the same values together plus retrieve an overall rating which I average and sort by. This works and is done using: Code: [Select] $sql="SELECT landlord_name, AVG(overall) FROM $tbl_name GROUP BY landlord_name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ Where Im finding it difficult though is I have 5 radio buttons with values from 1-5 and want one of them to be checked if the value matches the averaged overall rating. What I've tried is: Code: [Select] if (AVG(overall)==1){ $check1="checked";} if (AVG(overall)==2){ $check2="checked";} if (AVG(overall)==3){ $check3="checked";} if (AVG(overall)==4){ $check4="checked";} if (AVG(overall)==5){ $check5="checked";} then in the form: Code: [Select] <table width="600" border="1" cellspacing="0" cellpadding="3"> <tr> <td><? echo $rows['landlord_name']; ?></td> <td><div class="avg"><form> <input type="radio" value="1" disabled="disabled" checked= "<? $check1 ?>" /> <input type="radio" value="2" disabled="disabled" checked= "<? $check2 ?>" /> <input type="radio" value="3" disabled="disabled" checked= "<? $check3 ?>" /> <input type="radio" value="4" disabled="disabled" checked= "<? $check4 ?>" /> <input type="radio" value="5" disabled="disabled" checked= "<? $check5 ?>"/> </form></div> </td> </tr> </table> To make it a bit more difficult, the AVG(overall) value will not always be an integer from 1-5 and will need to be rounded to the closest one. Think i can use ROUND for this but dont know how to put it in. Thanks for your help in advance. As you can probably tell im new to php and still learning the basics. |