PHP - Build Color Palette With Loops
Hello everyone, i use content security policy set at self for javascript and css. unsafe-inline is forbidden. However, i want to allow the background to be changed in tow ways: foto selection and color selection if photos are turned off. I have accomplished all of this but unsafe inline does not help my purpose. I need the color to be accessible via css file. Thus, input color cannot be used here unless i dynamically crete a css file based upon a selection. I don't want to do this, so i hardcoded the 216 colors into a css file which is only 6kb. perfect! now i need to loop through the color values to dynamically create the 216 color palette. I've never done this before so i had to think about it and try to recognize a pattern. I noticed that red is first follwed by green and blue. so green and blue should be together inside a red loop. I've tested my theory and it works. yipee. Now i want to know if there is a better method for accomplishing this task? i've tried searching google with no luck at all. i don't know what to search for other than 'build a 256 color palette using php loops'. I really find nothing of value. Amazing! here is my code which is working. so can someone offer a more professional method? <?php declare (strict_types = 1); $rgb = ['00','33','66','99','cc','ff']; $colors = 0; foreach ($rgb as $red) { foreach ($rgb as $green) { foreach ($rgb as $blue) { echo $red . $green . $blue . ', '; ++$colors; } } echo '<br><br>'; } echo 'there are ' . $colors . ' colors in this palette'; exit; ?> Thank you very much and i hope that you all have a fantastic day 🙂 Edited July 3, 2020 by jodunnoSimilar TutorialsInstead of breaking down and actually learning how to use ajax, I'm thinking about trying to do something so I don't need a page refresh every time, and the filtered data is nearly instant. I just use the session array var, and build a new array from the rows that meet the conditions. I'm thinking of loading a two dimensional array into a session var, then use some input buttons, and use the post vars to filter the array based on a set of predefined conditions. ie status = 0, status = 1. It's a fairly small number of conditions applied to two different fields. So, I need to access specific fields within a row, and essentially create a new array either including or excluding that row depending on whether it met the condition. I'm struggling on several parts. 1. not sure how to build the array so that I can access specific fields, then not sure how to access those fields. Do I do this..... to build the array? .... Code: [Select] while($row = mysql_fetch_assoc($result)){ $array[] = array($row['field1'], $row['field2']); } I was thinking about using a foreach and is_array() to get to each row... Code: [Select] foreach($array as $key => $value){ if(is_array){ foreach($value as $k => $v){ if($v[0] == 1){ //stuck here $v[0] is not a field, it's the first char of the string. not sure how to access a field $new_array[] = $value; //stuck here. I need to put the whole row back into the array if the condition was true. seems like I would have to use the field selectors and rebuild the array. } } } } What would you do? Open to any ideas. HI, coming from a .net background and picking up php as I go along, I was wondering what the best way of designing the following task is in php. It's part of an appointmnet reminder app and the admin can amend the message that is sent out. The default message is currently stored in a db table and displayed in a multi line box on the admin web page. for example, "This is a an appointment reminder for *patient name*. You have an appointment on *date* with *customer name*." There's two parts relating to the message process. 1. Allowing the admin to amend the message (but ensuring the *variable markers* are left in tact, so I know where to stick the variables for part 2) 2. When the messages are being sent out (for each loop), inserting the *variables* into the message. I have no problem getting hold of the *name*, *date*, *customer* for each iteration in the for each loop. I'm sure people have done stuff like this before and in .net I would use a stringbuilder object but like i say, I'm not all that groovy on php at the mo. I was thinking of maybe a function that accepts thats passed the message, name, date, customer or something.. thanks Hi, I have to build some reports based on mysql queries. Nothing fancy, just text, columns... There are a lot of paid softwares but I can't (and don't want to) spend any $$ right now... So, considering that I want very simple reports almost like a table with heading and subtotals, I should write it myself. But I don't know how (still...). I'm looking for tips, tutorials, ebooks... anything that explains how to make a very simply report. Regards, Pedro. I have two questions, I was wondering what would be the best method to go about building client side API functions on top of a already built API eg. http://docs.whmcs.com/API:Functions
We would like to provide our clients access to API functions related to their accounts without giving them access to the whole Admin API where they can see a lot of our other client information.
The other question we have an API built using Basic HTTP Auth for API authenication (HTTPS). eg curl username:password http://api.etc.com) If so what would be the best way to secure this method?
Thank you Hi there, i have a problem regarding a editor that I am building, I am fairly new to php, but this is what i have so far: Code: [Select] <?php $dirname = "."; $dir = opendir($dirname); ?> <form action="editor.php" method="POST"> <select> <?php while(false != ($file = readdir($dir))) if (strpos($file, '.php',1)||strpos($file, '.html',1)||strpos($file, '.css',1) ) { { if(($file != ".") and ($file != "..")) { echo("<option><a href='$file'>$file</a></option>"); } }} ?> </select> <input type="submit" value="Submit" /> </form> <br /> <center> <form > <textarea rows="80" cols="130"> <?php include $_POST["$file"]; ?> </textarea> </center> The code produces a drop down list of any html, php or css files in the current directory and I want it to be able to show the selected file from the drop down list in the textarea so that I can edit it, I also am not sure how to save the file, would this be a file write method? any help would really be appreciated as I've been stuck on this issue for hours an its doing my nut in!!! Thanks SF Is it overkill to use PHP/MySQL to query my database, retrieve the universe of Questions, and then dynamically build a Form? I have a "Q&A Form" with a whopping 10 Questions. I suppose dynamically building the Form has the advantage that I always have the most up-to-date Questions and Question Text, but them again, if there is a database issue, I have a larger issue... Thoughts? Debbie Hello. I would like to build a survey that I can use on an iPad so that I can go out in the field and gather data from people. What would be the best way to accomplish this? I'm not sure what limitations even exist on an iPad - like can you have a webserver like MAMP? It seems to me that using something like Angular or whatever might make sense since you can build a working app all in one, but then I don't even know traditional Javascript. Just looking for a quick way to build something to allow me to survey people without making this a major project.\ Thanks. Hello again, guys! I'm trying to do this: Get $user_ID -> SELECT FROM favorites WHERE user="$user_ID" -> Now I should create an array with the ID of all the results of the previous command -> SELECT FROM books WHERE genre="$favorites_ID" -> populate a html table. The part I've no idea about how to do is building an array with the results and then using the SELECT command, find in the other tables the match. Could you please give me a hand - one more time? Hiya peeps! I can't seem to build a preg_match pattern that works. This is what I need to do. "[" . $errorID . "]='HERE IS WHAT I NEED TO DISPLAY';" Does anyone have any ideas on how I would build this regex string? Many thanks, James. OK here is what I have going on right now. Currently I'm trying to build a excel spread sheet into a dynamic form via php. The results are basically questions and are stored each week so for one section they may be asking how many visitors, employee's , etc.. now some of these values that are being entered are going to be used in another question per-say but the result may come from other values that were already submitted so these questions would not be shown in the form that needs to be made later on. The form I'm having trouble with is the initial form to help generate the formula's for these different questions. So what I was going to start doing was have it list all the questions with a check box next to the question if the formula for said question was something like add these two questions and the divide by this set of questions or a whole number then it would display a list of questions for adding together and the get the total from that set and then do a expression afterwards like adding, subtracting, multiplying or dividing. So I was thinking I should list like a set of buttons I think in the beginning. What is the first task at hand Totaling, Adding, Subtracting, Dividing, Multiplying and then when they click on this it would refresh the page and bring up a box that lists all the different questions for them. Then saving the values as which ever button they clicked and once they do this. Then they could either click on say a more button which would pass the values as a array back to the page and continue on or they could click submit and pass the values into a db field as a formula but this is my first concept and would like to know if there may be a better way of doing it. How could I build an interactive text system? It should work like this: Text is displayed. 1-3 options (a situational amount of them) to answer displayed. Example: Are you male? Yes No You choose yes or no and it leads you to another questions based from your previous answer. Example: (a follow up to the 1st one) So you're male. Do you like cars then? Answers. And it goes on and on. The thing I need help with is the answers. I need to show them based by the previous answer but don't know how, any help? So, I need to build a table based on this table: Code: [Select] create temporary table downline ( depth int, member_id int, full_name varchar(50), level int, referrer_id int, country char(2) ); I need to make a table to show each members downline (the people they referred to the site), it needs to be unlimited levels deep, and we have some members that have 25+ levels in their downline, where level 20 has 15,000+ people. Level 1 = your downline Level 2 = your donwline's downline Level 3 = your downline's downline's downline ect. I have this loop (after the temp table is built) which needs to build a table on the page. So, I can not get this table display right for the members downline, any suggestions? // Build the current users downline and add it to the temporary table $downline = mysql_query("select * from downline order by depth"); while($row = mysql_fetch_assoc($downline)){ if($row['depth'] != $depth){ $depth_id = $row['depth']; $content .= "<tr id='main_lvl_$depth_id' class='hiddenInfo' onclick='showHide(this);'><td style='text-align: center;color:#4d53c1;font-weight: bold;' class='w_border'><span class='signs_s'>".$this->dict['mLevels_Level']." $depth_id : </span><span class='signs'>".count($down)." ".$this->dict['mLevels_Members']." </span></td></tr><tr id='lvl_$depth_id' style='display:none;'><td class='w_border' style='text-align: center;'><table style='width:100%;'>"; $i = 0; $content .= "<tr> <th>Member ID (Sponsor ID)</th> <th>Member Name</th> <th>Country</th> <th>Member Level</th> </tr>"; } $class = ($i%2) ? 'color1NL' : 'color2NL'; $content .= "<tr id='_{$key}_' class='$class'><td class='width33'><a name='_".$row['member_id']."'></a><a href='?mid={$row['member_id']}'>#{$row['member_id']}</a> (<a href='?mid=".$row['referrer_id']."'>#".$row['referrer_id']."</a>)</td><td class='width33'>".$row['full_name']."</td><td>".$row['country']."</td><td class='width33'>".$row['level']."</td></tr>"; $i++; if($row['depth'] != $depth){ $content .= "</table></td></tr>"; } $depth = $row['depth']; } The following attachment has a working copy. The reason we don't stay with this is because it doesn't work with members who have large downlines, we run out of memory in php, and this hopefully will solve this problem. Hey PF. I'm trying to build some better coding habits, so what tips do you guys have? Of course there are obvious things such as well-commented code, neat structure, etc... But I'm looking for some more "TECHNICAL" tips that might be unspoken. For example, when is a good time to use a variable, opposed to a constant? I notice that a lot of programmers define their database settings with define(), while others just use a $variable. Is this personal preference or maybe its something I'm missing? I'm looking for ALL tips. Any information that you have, please share it. It will help make me (And anyone else reading this), a better coder. Thanks in advance. and if this is not the proper forum, please move it! =] Ok so I'll try to explain what I'm trying to do the best I can. I want to build an array that allows me to add/remove/modify the variables used at any point in time without having to rebuild or rewrite a ton of new code. For example, below is an example list of variables I'd like to use in the array, followed by the code I would like to be automatically repeated. Example Variables: $materialName1, $materialName2, $materialName3, $materialName4, $materialName5, $materialName6 etc etc etc Example Code to repeat: Code: [Select] echo "<tr><td>Material: $materialName1</td><td>Rate: $materialName1Rate</td><td>Weight: $materialName1Weight</td></tr>"; Hopefully that makes sense. As always, very appreciated. I'm trying to build an array in a foreach loop, but when I got to echo the results it only displays the first character of the string, but if I do a print_r on the array it show the data fine. $msgColor1 = array(); foreach ($playerName1 as $value) { $msgColor1['name'] .= $value[$i]; $i = $i + 1; } print_r show the data but when i do foreach ($msgColor1 as $test) { echo $test['name']; } Only shows the first character in the string I'm confused how to get the chat object to work with the pushes/pulls, and don't know where I'm going wrong. Here's the basics of what I need to know without reloading the page:
how do I push new data to the server
how do I push new data to the client
how do I not rebuild the data client has every time
I may need to know more, but that's what I know I need to be able to do so far.
This topic has been moved to Installation in Windows. http://www.phpfreaks.com/forums/index.php?topic=358758.0 Hi, I am trying to recursively build another array based on the one I get back from our CRM api. The array I get back looks like this: Code: [Select] [1] => stdClass Object ( [description] => Description Text [label] => Product [name] => Product [sobject] => KnowledgeArticleVersion [topCategories] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [label] => Apple [name] => Apple ) [1] => stdClass Object ( [label] => Orange [name] => Orange ) [2] => stdClass Object ( [label] => lemon [name] => lemon ) ) [label] => Templates [name] => Templates ) [1] => stdClass Object ( [label] => Connector [name] => Connector ) [2] => stdClass Object ( [label] => AeroView [name] => AeroView ) ) [label] => AeroWare [name] => AeroWare ) [1] => stdClass Object ( [label] => BackOffice [name] => BackOffice ) [2] => stdClass Object ( [label] => OutWare [name] => OutWare ) [3] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [label] => ERA [name] => ERA ) [1] => stdClass Object ( [label] => Kairos [name] => Kairos ) ) [label] => InWare [name] => InWare ) ) [label] => All [name] => All ) ) The child categories could be any level deep. I would like put it in an array something like this: Code: [Select] Array ( [label] => Cat 1 [level] => 0 [children] => Array ( [label] => Sub Cat 1 [level] => 1 [children] => Array ( [label] => Sub Sub Cat 1 [level] => 2 ) ) ) I have tried so many things but I just can't get it right. Any assistance would be greatly appreciated. Thanks Peter This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346015.0 |