PHP - Toggle Background Colour
Hi. I am looking for a way to have a button that toggles the background colour of my website.
So for instance, I will have one button called 'switch to light', when its clicked it switches the colour of the background to a light colour, and another button replaces this that says 'switch to dark', and so on. I have turned to PHP because it appears to be the only way I would be able to have the change saved throughout the site, when pages are refreshed. However, I am a complete newbie, so have no idea what to do! Anyone that can help is a life saver! Thanks Similar TutorialsI have got a code working to generate a menu from a mysql table, but I wan't to know if it is possible to have the background colour change to a third option when active. I have 1 background colour for 'off', one for mouseover, but can't figure out how to tell it what they current page is so that it will use a different css class value, as the page obviously reloads after the link is clicked. Is it possible (hope my explanation makes some sence!) My code: At the moment mainNav a: and mainNav a:hover work ok but what I want is a mainNav a:active to stay on after the page has loaded Code: [Select] <?php //function to nest the menu tree function nest_child(&$nodes, $current) { if (!isset($nodes) || count($nodes) < 1) { return; } foreach ($nodes as $id => $item) { if ($current['parentdocid'] == $id) { if (!isset($item['children'])) { $item['children'] = array(); } array_push($item['children'], $current); $nodes[$id] = $item; } else { nest_child($item['children'], $current); } } } //functions to display the tree and expand as appropriate function menu_display($nodes, $display_id) { if (!isset($display_id) || ($display_id == '')) { $display_id = 1; } $result = node_display( array( 'doc_id' => 1, 'children' => $nodes ), $display_id ); return $result[1]; } function node_display($node, $display_id) { global $ROOT; $found = false; $text = ''; if (isset($node[children])) { foreach ($node[children] as $id => $child) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$child[doc_id]'>$child[doc_name]</a>"; $result = node_display($child, $display_id); if ($result[0]) { $found = true; $text .= "<ol>$result[1]</ol>"; } if ($child[doc_id] == $display_id) { $found = true; if (isset($child[children])) { $text .= "<ol>"; foreach ($child[children] as $id => $grandchild) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$grandchild[doc_id]'>$grandchild[doc_name]</a>"; } $text .= "</ol>"; } } $text .= "</li>"; } } if ((!$found) && ($display_id != 1)) { $text = ''; } return array($found, $text); } ?> <ul class="menu"> <?php //retrieve all the menu elements $result = mysql_query('SELECT * FROM docs ORDER BY doc_order ASC'); $menu = array(); while ($row = mysql_fetch_assoc($result)) { $menu[$row['doc_id']] = $row; } //nest the elements foreach ($menu as $id => $item) { if ($item['parentdocid'] != 1) { nest_child($menu, $item); unset($menu[$id]); } } //display the tree print menu_display($menu, $doc_id); ?> </ul> 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 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310618.0 I'm trying to show my data under the toggle button according to the order_id. But i do not know why when i click on my toggle button it does not work. I do not know what is wrong with it. Any advice will be appreciated. <?php $dsql = "SELECT o.order_id , o.purchase_price , o.order_datetime, u.id, u.user_fullname , p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."' ORDER BY o.order_id DESC"; $dquery = $conn->query($dsql); $tot_orders = mysqli_num_rows($dquery); if (!mysqli_num_rows($dquery)) { echo ' <div class="col-12"> <div class="badge badge-danger">No Orders Found</div> </div> '; } else { while ($drow = $dquery->fetch_assoc()) { ?> <tr> <td> #<?php echo $drow['order_id']; ?> </td> <td> <?php echo $drow['user_fullname']; ?> </td> <td> RM<?php echo number_format($drow['purchase_price'],2); ?> </td> <td class="text-center"> <a style="text-decoration: none;color: #000;" title="View Details" data-toggle="collapse" data-target="#products-details<?php echo $drow['order_id']; ?>"> <i class="nc-icon nc-minimal-down" onclick="changeToggleIcon(this)"></i> </a> </td> </td> </tr> <?php $p_sql = "SELECT o.order_id , o.purchase_price , o.order_datetime , o.quantity , o.quantity_unit, u.id, u.user_fullname , p.id, p.product_title , p.product_photo , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."'" ; $p_query = $conn->query($p_sql); while ($p_row = $p_query->fetch_assoc()) { ?> <tr class="collapse" id="products-details<?php echo $drow['order_id']; ?>" > <td style="border-top: none; font-size: 10px;"> <img src="https://dev.gopasar.today/images/product-main/<?php echo $p_row['product_photo']; ?>" style="height: 50px; width: 50px;"> </td> <th style="border-top: none; font-size: 10px;"> <?php echo $p_row['product_title']; ?> </th> <th style="border-top: none; font-size: 10px;"> Order Quantity :<?php echo $p_row['quantity']; ?><?php echo $p_row['quantity_unit']; ?> </th> <th style="border-top: none; font-size: 10px;"> RM <?php echo $p_row['purchase_price'];?> </th> </tr> </div> </div> </div> <?php } } } ?>
Hi All, I have a page where people can enter the name of food, like you would order in a restaurant (would appear on the menu). They can set if the food is gluten free, nut free, vegan etc. I am wanting to use buttons that can be clicked going red if they are not gluten free or not vegetarian and green if they are vegan or vegetarian. I have working code that does this but i dont feel like i am being efficient with how i am writing it as it is turning into a lot of repeated code. I would appreciate some help pointing me in the right direction. function popManageMenuModal($conn, $miid){ $stmt = $conn -> prepare(' SELECT menu_item_name, menu_item_is_vegan, menu_item_is_vegitarian, menu_item_is_gf, menu_item_is_nf, menu_item_is_df FROM ssm_menu_items WHERE menu_item_id = ? '); $stmt -> bind_param('i', $miid); $stmt -> execute(); $stmt -> bind_result($miname, $miisvegan, $miisveg, $miisgf, $miisnf, $miisdf); $stmt -> fetch(); if($miisvegan == '1'){ $vegansel = 'btn-success'; $vegan = 'Vegan'; $veganop = 'Is'; }else{ $vegansel = 'btn-danger'; $vegan = 'Vegan'; $veganop = 'Not'; } if($miisveg == '1'){ $vegsel = 'btn-success'; $vegi = 'Vegi'; $vegop = 'Is'; }else{ $vegsel = 'btn-danger'; $vegi = 'Vegi'; $vegop = 'Not'; } $output = ""; $output .= "<form><div class='form-group'><label>Menu Item Name</label><textarea class='form-control'>$miname</textarea></div>"; $output .= "<div class='form-inline'>"; $output .= "<div class='drButton btn $vegansel' data-value='$miisvegan'>{$veganop} {$vegan}</div>"; $output .= "<div class='drButton btn $vegsel' data-value='$miisveg'>{$vegop} {$vegi}</div>"; $output .= "<div>$miisvegan, $miisveg, $miisgf, $miisnf, $miisdf</div>"; $output .= "</form>"; return $output; } $(document).on('click','.drButton', function(){ var polarity = $(this).data("value") if(polarity == '0'){ $(this).addClass("btn-success") $(this).removeClass("btn-danger") $(this).data("value", '1') return } if (polarity == '1'){ $(this).addClass("btn-danger") $(this).removeClass("btn-success") $(this).data("value", '0') return } });
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=348953.0 Hello all, This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=344421.0 I'm wondering how I can find the x, y coordinates on an image in PHP where a specific colour lies. If there was a #000000 coloured pixel located on 127, 205, how could I use PHP to find the 127, 205 by just telling it #000000? Hi I have a table that populated by a recordset, and wondered whether is was possible to make a row background colour = red where a particular cell = some text? I have been searching around and not managed to find anything of use. Any help would be appreciated. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=355418.0 Hey i got one problem i want add background how i should make it any help will be welcome Code: [Select] <?php //source file $file = "test.txt"; //images size $high = "200"; $wide = "400"; //generate image $data = file($file); $im = @ imagecreate($wide, $high) or die("Error"); $bc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); $lines = (int) $high / 10; for ($t = 0; $t < $lines; $t++) { imagestring($im, 3, 4, 4, $data[$t], $tc); imagestring($im, 3, 4, 4 + ($t * 10), $data[$t], $tc); } //header("Content-type: image/png"); //imagepng($im); imagepng($im,"pildid/1.png"); imagedestroy($im); ?> I envision running code in the background without slowing my own PHP page render. This code accesses optional "Additional Information" via a 3rd party server API ("www.example.com/Additional_Information.php?SKU=1234567"). Unfortunately, it takes a full 10 seconds to retrieve the data from the 3rd party server, and, not all visitors will need this "Additional Information." My own server is fast -- it retrieves mySQL data from my server and renders the result to the Visitor in less than 4 milliseconds. Because it takes an average Visitor about 10 seconds to actually READ my entire page (description, photos, etc.), this would be a perfect time to run a script in the background so that if the Visitor chooses to click the "Additional Information" link, the data will already be available (because the background script would run in the background and post its results to my own mySQL server while the Visitor was busy reading). I've been studying asynchronous cURL calls, opening sockets, forking cURL, and even using cURL to call another cURL script on my server. These seem to slow down my PHP page render. Because not all visitors will want this "Additional Information," I don't want to slow my webpage down for everyone. Is there a way to have code 'truly run in the background' and post its result to my super-fast mySQL server, so if a Visitor does click on the "Additional Information" link, they'd get instant results from my own server? Edited December 2, 2018 by StevenOliverOriginal question revolved around cURL. I'm trying to "step out of the box" with the awareness there are other methods than cURL. Hello all, im fairly new, but i have a question that i cant answer. is it possible to use the contents of a folder as a website background as in my pictures folder would be a tile of the same size images as my website background? and if i upload some more photos it automatically updates the background? and it would get gradually smaller as the more pictures came into the folder like 2 pics would be side by side 4 would be one in each corner and 6 and 8 and so forth so basically it sizes them equally so that it fills the page. any ideas ? cheers I have a page that displays various articles. I would like to show a background image for each article. Let's say I have articles for beaches. I would like to have a beach photo. Airplane article, show airplanes, etc. How can I accomplish this. I have an action that will take a long time to finish, so how can I run this action in background? So I will not have to wait it ends... helllo when people visit my site the background of my site isnt there, but then the log in, it appears, so it only works when thye are logged in, can someone please look over y code and see why this is happening, i have been stuck on this for 1 week now Code: [Select] <?php // Start_session, check if user is logged in or not, and connect to the database all in one included file include_once("scripts/checkuserlog.php"); // Include the class files for auto making links out of full URLs and for Time Ago date formatting include_once("wi_class_files/autoMakeLinks.php"); include_once ("wi_class_files/agoTimeFormat.php"); // Create the two objects before we can use them below in this script $activeLinkObject = new autoActiveLink; $myObject = new convertToAgo; ?> <?php // Include this script for random member display on home page include_once "scripts/homePage_randomMembers.php"; ?> <?php $sql_blabs = mysql_query("SELECT id, mem_id, send_id, the_blab, blab_date FROM blabbing ORDER BY blab_date DESC LIMIT 30"); $blabberDisplayList = ""; // Initialize the variable here while($row = mysql_fetch_array($sql_blabs)){ $blabid = $row["id"]; $uid = $row['send_id'] != 0 ? $row['send_id'] : $row['mem_id'] ; $the_blab = $row["the_blab"]; $notokinarray = array("fag", "gay", "shit", "fuck", "stupid", "idiot", "asshole", "cunt", "douche"); $okinarray = array("gaybo", "homosexual", "poo", "bugger", "dumb", "jerk", "sphincter", "vagina", "douche"); $the_blab = str_replace($notokinarray, $okinarray, $the_blab); $the_blab = ($activeLinkObject -> makeActiveLink($the_blab)); $blab_date = $row["blab_date"]; $convertedTime = ($myObject -> convert_datetime($blab_date)); $whenBlab = ($myObject -> makeAgo($convertedTime)); //$blab_date = strftime("%b %d, %Y %I:%M:%S %p", strtotime($blab_date)); // Inner sql query $sql_mem_data = mysql_query("SELECT id, username, firstname, lastname FROM myMembers WHERE id='$uid' LIMIT 1"); while($row = mysql_fetch_array($sql_mem_data)){ $uid = $row["id"]; $username = $row["username"]; $firstname = $row["firstname"]; if ($firstname != "") {$username = $firstname; } // (I added usernames late in my system, this line is not needed for you) /////// Mechanism to Display Pic. See if they have uploaded a pic or not ////////////////////////// $ucheck_pic = "members/$uid/image01.jpg"; $udefault_pic = "members/0/image01.jpg"; if (file_exists($ucheck_pic)) { $blabber_pic = '<div style="overflow:hidden; width:40px; height:40px;"><img src="' . $ucheck_pic . '" width="40px" border="0" /></div>'; // forces picture to be 100px wide and no more } else { $blabber_pic = "<img src=\"$udefault_pic\" width=\"40px\" height=\"40px\" border=\"0\" />"; // forces default picture to be 100px wide and no more } $blabberDisplayList .= ' <table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC"> <tr> <td width="7%" bgcolor="#FFFFFF" valign="top"><a href="profile.php?id=' . $uid . '">' . $blabber_pic . '</a> </td> <td width="93%" bgcolor="#EFEFEF" style="line-height:1.5em;" valign="top"><span class="greenColor textsize10">' . $whenBlab . ' <a href="profile.php?id=' . $uid . '">' . $username . '</a> said: </span><br /> ' . $the_blab . '</td> </tr> </table>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta name="Description" content="Cookbookers is a community website for people to create and share recipies, make friends or join up with old friends" /> <meta name="Keywords" content="cookbookers, cook, cookbook, cooks, chefs, chef, cookery, book, books, cooking, community, share, communicate,recipies, free, friends, register, shareing, " /> <meta name="author" content="lachlan mcgrath"/> <meta name="ROBOTS" content="INDEX,FOLLOW"/> <meta name="google-site-verification" content="fbI5fgCcTZh3cTw3deqVLevmvZkSOj3C-EwMDS7XMPI" /> <title>CookBookers - Your online cooking community</title> <link href="style/main.css" rel="stylesheet" type="text/css" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <style type="text/css"> .style1 { font-family: Arial; font-size: 18px; } #Layer1 { height:210px; background-image: url(images/top_container_bg_recipes_new.gif); } body { margin-bottom: 0px; background-image: url(images/bg.jpg); background-repeat: repeat-x; background-color: #360904; } .boxHeader { border:#999 1px solid; background-color: #FFF; background-image:url(style/accountStrip1.jpg); background-repeat:repeat-x; padding:5px; margin-left:19px; margin-right:20px; margin-top:6px; color:#060; text-decoration:none; } .style3 {font-size: 20px} #apDiv1 { left:294px; top:308px; width:848px; height:59px; z-index:1; } #apDiv2 { left:283px; top:159px; width:288px; height:126px; z-index:2; } #filter td { filter:alpha(opacity=50); -moz-opacity:0.5; opacity: 0.5; } </style> <script language="javascript" type="text/javascript"> function toggleSlideBox(x) { if ($('#'+x).is(":hidden")) { $(".editBox").slideUp(200); $('#'+x).slideDown(300); } else { $('#'+x).slideUp(300); } } </script> </head> <body> <p> <?php include_once "header_template.php"; ?> </p> <center> <table cellpadding="0px" cellspacing="0px" style="border:0px solid #666666;" width="75%"> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <table cellspacing="0px" border="0" align="center" width="54%" height="25%" style="background-color:transparent"> <tr> <td><a href="http://www.facebook.com/pages/Cookbookers/140615036007324"><img src="images/facebook_button.png" width="87" height="87" align="absmiddle" /></a> <a href="http://twitter.com/cookbookers"><img src="images/Twitter_button.png" width="87" height="87" align="absmiddle"/></a></td> <tr> <td><img src="images/banner_catering.jpg" width="835" height="262" /></td> </tr> </table> <tr></tr> <tr> <td><table width="59%" height="22" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color:#F2F2F2; border:0px solid #666666;"> <tr> <td valign="top" colspan="2" style="background-color:#F2F2F2; border:0px; padding:10px;"> <table border="0" cellpadding="6"> <tr> <td class="style1">Newest Members:</td> <td> <?php print "$MemberDisplayList"; ?> </td> </tr> </table> </td> </tr> <tr> <td width="358" valign="top" style="width:250px; overflow:auto;"> <table width="358" height="152" align="center" cellpadding="4" bgcolor="#F2F2F2" style="border: 0px;"> <tr><td width="344" colspan="2">Recent Posts</td></tr> <tr> <td bgcolor="#F2F2F2" valign="top"><?php print "$blabberDisplayList"; ?></td> </tr> </table> </span> </td> <td width="557" valign="top"> <p>Hello and welcome to cookbookers.com! We are an online cooking community where you can share recipes and communicate with others that love to cook. In your account you can add recipes to share with the public or you can just keep them for yourself inside you own personal cookbook. There'll be more work happening to the website during the next couple of weeks, we're gonna be enhancing the website a bit more, adding garnishes, making it a bit more appealing for everyone. We'll be adding a few new features shortly as well: a forum, you'll be able to comment on recipes and have yours commented, a live chat. But that's just a few of them.</p> <p>If you have any suggestions for the site or any questions; feel free to contact me thought the website, send me a private message or just blab on my page. My name is Lachlan Mcgrath.</p> <p>So please join up, add recipes and make new friends on cookbookers.com today!</p> <p> </p> <p>Happy Sharing!</br> </p> <p>Lachlan McGrath</br> </p> <p>Owner/creator. </p> <p> <?php if(isset($_SESSION['username'])) { } else { include('login.php'); } ?> </p> <p> </p></td> </tr> </table> <p> <?php include_once "footer_template.php"; ?> </p> <p><!-- Histats.com START (standard)--> <script type="text/javascript">document.write(unescape("%3Cscript src=%27http://s10.histats.com/js15.js%27 type=%27text/javascript%27%3E%3C/script%3E"));</script> <a href="http://www.histats.com" target="_blank" title="free stats" ><script type="text/javascript" > try {Histats.start(1,1395398,4,198,85,17,"00001000"); Histats.track_hits();} catch(err){}; </script></a> <noscript><a href="http://www.histats.com" target="_blank"><img src="http://sstatic1.histats.com/0.gif?1395398&101" alt="free stats" border="0"></a></noscript> <!-- Histats.com END --></p> </body> </html> thanks! Hey guys, I've hit a huge obstacle in my coding process of a script I am writing. It is basically an uploading interface script and it works like this. I have files on my server and I want a user to click a button which fires a php script which in turn fires a bash script which IN TURN fires the uploading program (plowshare). So to make it simple: user logs in, sees upload button. Clicks it, file starts uploading. I then want the user to see "upload initiated" and that's it. The problem is that with what I have now, the script just won't finish loading until the file has been uploaded and as a matter of fact I don't even think it is uploading anything :S Here are the scripts: PHP interface to call the bash script: Code: [Select] <?php error_reporting(E_ALL); function run_in_background($Command, $Priority = 0) { if ($Priority) $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!"); else $PID = shell_exec("nohup $Command 2> /dev/null & echo $!"); return($PID); } function is_process_running($PID) { exec("ps $PID", $ProcessState); return(count($ProcessState) >= 2); } $file = $_GET['file']; // Location of file relative to the index $where = $_GET['where']; // Absolute index location $absolute = '/var/www/vhosts/animekyun.com/httpdocs/icarus/'; $where = $absolute . $where; //$outfile ='log'; echo $where . $file . '<br>'; echo "<h2>The upload has been initiated!</h2>"; $ps = run_in_background("/bin/sh uploadparser.sh $file $where > $outfile"); while(is_process_running($ps)) //echo $output; ?> Bash script to call uploading program: Code: [Select] #!/bin/sh { FILE=$1 WHERE=$2 FILENAME="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_mu_$FILE" FILENAME2="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_multi_$FILE" /usr/local/bin/plowup megaupload "$WHERE$FILE" >> "$FILENAME".txt 2>&1 /usr/local/bin/plowup multiupload "$WHERE$FILE" >> "$FILENAME2".txt 2>&1 } & this works fine when I pass the variables as arguments in CLI I hope i have been clear enough, it does seem rather confusing So I'm new to PHP GD, I cant understand why the PNG image will not go transparent, it's just showing a white background.
Could anyone help me out with this?
Spoiler Hi all,
Any idea what Pinterest uses to make the background move please?
I searched everywhere and cannot find the answer:
https://www.pinterest.com/
I need the same type of background movement + popup on my site, it looks so nice!
Thank you,
Ben
|