Jump to content

Search the Community

Showing results for tags 'function'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 6 results

  1. I am trying to convert colors from Hex to HSL (Not HSL to Hex). I am using a PHP function for this purpose. But It's not working properly for some colors. For example for #e04c4c the HSL should be (0, 70%, 59%) which it isn't the case with the function. function hexToHsl($hex) { $red = hexdec(substr($hex, 0, 2)) / 255; $green = hexdec(substr($hex, 2, 2)) / 255; $blue = hexdec(substr($hex, 4, 2)) / 255; $cmin = min($red, $green, $blue); $cmax = max($red, $green, $blue); $delta = $cmax - $cmin; if ($delta === 0) { $hue = 0; } elseif ($cmax === $red) { $hue = (($green - $blue) / $delta) % 6; } elseif ($cmax === $green) { $hue = ($blue - $red) / $delta + 2; } else { $hue = ($red - $green) / $delta + 4; } $hue = round($hue * 60); if ($hue < 0) { $hue += 360; } $lightness = (($cmax + $cmin) / 2) * 100; $saturation = $delta === 0 ? 0 : ($delta / (1 - abs(2 * $lightness - 1))) * 100; if ($saturation < 0) { $saturation += 100; } $lightness = round($lightness); $saturation = round($saturation); //return "hsl(${hue}, ${saturation}%, ${lightness}%)"; return array($hue, $saturation, $lightness); } This is how I used it: $templatePrimaryColor = '#e04c4c'; $templatePrimaryColor = str_replace("#", "",$templatePrimaryColor); list($h,$s,$l) = hexToHsl($templatePrimaryColor); $primaryColor = "hsl(${h}, ${s}%, ${l}%)"; This is the output: echo '<pre>',print_r(hexToHsl($templatePrimaryColor)).'</pre>'; Array ( [0] => 0 [1] => 99 [2] => 59 ) 1 Does anyone know what is the problem there? Thank you.
  2. Hello! I'm starting to learn php and for practice I tried to resolve a simple exercise. the idea is to write a php function that inputs a tabe and returns +1 if positive numbers in the table are more than the negative ones. and return -1 if negative numbers in the table are more than the positive ones. 0 if they are equal. this is my code for the function starting from line 8 function plusmin ($tab) { $n = count($tab); $plus = 0; $min = 0; for ($i = 0; $i <= $n; $i++) { if ($tab[$i] > 0){ $plus++; } elseif ($tab[$i] < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; } and just to test it I created a table manually $tab[0] = 1; $tab[1] = -5; $tab[2] = -4; $tab[3] = 7; $tab[4] = -8; $tab[5] = -3; $tab[6] = 2; $tab[7] = 0; $tab[8] = -6; $tab[9] = -9; $k = plusmin($tab); echo $k; when I execute it It works, it shows for the case -1 but the browser shows this error Notice: Undefined offset: 10 in C:\Users\ahmed\PhpstormProjects\Exam 2013\tab.php on line 13 line 13 is this one if ($tab[$i] > 0){ Notice: Undefined offset: 10 in C:\Users\ahmed\PhpstormProjects\Exam 2013\tab.php on line 16 line 16 is this one elseif ($tab[$i] < 0){ I dunno what's the problem. and I know it will turn out to be a stupid problem but hey that's how we all learn. could anyone help? Thanks in advance
  3. Hi, I've inherited some code on a system from another person. I'll be the first to admit that I'm not a PHP pro, I am self taught, and use it sparingly for personal projects mainly. So this is a bit beyond my skill level, and I was hoping for some advice: The system is a glorified calendar, with a lot of our own data being slapped on top of it and presented nicely. The issue I have thoguh is that due to the way the calendar is generated, I cant make the height of the days move dynamically based on what content gets dropped into each day on the calendar. If one day is busy and has 8 events drop into it, they will overflow the days cell. I wanted to adjust the height of ALL cells on a month view calendar to the heighest required height of all cells in that view. What I was going to do, is +1 to a coutner for every event (or block) that is generated for each day (days are looped through a private function), and commit that number to an array. At the end fo the loop (after all days ahve been counted and have a value in the array), I was going to use max() on the array, pull the largest number, calculate the days cell hiehgt from that and apply it via CSS at page level. I've summarised the code in effect here (psuedo code, not real PHP): class Calendar { public $heights; private fucntion dayLoop($cellNumber) { $heights = []; //array $block_count = 0; //counter while(mysqlrowdata) { [code for mysql operations] $block_count++; //increment the count } $day_height = ($block_count * 16) + 18; //do some math specific to my application $this->heights[] = $day_height; //commit calc'd value to array //array_push($heights, $day_height); //this was a previosu attempt, i dont think i should use array_push here..?? } } That function, and others is called from the front end pages to generate the calendar. If I do a: var_dump($heights); after it on that page, all I get returned on screen is "Array ( )" I tried changing the private function to a public one, but this did not affect the outcome. Anyone have any ideas on what I'm doing wrong? Is my logic sound? Can I commit values to an array inside a loop in a public OR private function and then reference that array outside of the loop? I defined $heights as public in the class too, but that didnt change the outcome either. Thanks.
  4. up votedown votefavorite I've been scraching my head for hours over this problem. I'm basically trying to fetch values from a loop inside a function to pass it to another foreach loop to get the desired results. And it is not working as I intend to. please, point me in the right direction. Here is the code: function ff($s) { $project=""; foreach ($s as $i=> $r ){ $r["friend_one"] == $_SESSION['uname'] ? $friends[]= $r["friend_two"] : $friends[] = $r["friend_one"]; $friend=$friends[$i]; $totalids=$project->totalids($_SESSION['uname'],$friend); } return $totalids; } $totalid= ff($f); print_r($totalid); foreach ($totalid as $v){ $id=$v['user_id']; //other logic to get desired result }
  5. Hi all, I am trying to pass 4 variables from one php page to another php page containing a google maps api. The variables I am passing are geo coordinates. at the end I want to show the map on my php page however I am struggling with linking php and javascipt together. This is what I have so far: external function page: http://pastebin.com/NAKHmKxW [PART OF MAIN PHP PAGE] <div class="row"> <?php include_once("function_maps.php"); initMap($latitude, $longitude,$row['Latitude'],$row['Longitude']); ?> </div>
  6. Say I have this records table. RECORDS TABLE record_id | sponsor_id | user_id | plan_id ------------------------------------------------------------------------------ 1 user5 user6 5 // I am this user. 2 user3 user5 3 3 user3 user4 4 4 user2 user3 4 5 user2 user2 2 6 user0 user1 5 I am "user6" and my sponsor is "user5". What I want to do is find the same "plan_id" from my sponsors, no matter how far up I have to do. For eg. My current plan id is "5". My sponsor is "user5". If I look for "user5" in the user_id column, I would find that he only has plan "3" id. So I go to his sponsor, which is "user3" and find him in the user_id column. That user's plan id is "4" so it does not match my plan id either. I repeat the same process by going to his sponsor and his sponsor and so on until I find the plan id that matches me. So for this table example, that would be "user1". I only want to retrieve the first result that matches my plan id. How do I go on about coding this function? Normally I can do these queries to go up limited amount. But I am looking for a more proper function that lets me search my sponsors unlimited times. $find_plan_id = $db->prepare("SELECT sponsor_id, plan_id FROM records WHERE user_id = :user_id"); $find_plan_id->bindParam(':user_id', $user_id); $find_plan_id->execute(); $result_find_plan_id = $find_plan_id->fetchAll(PDO::FETCH_ASSOC); if(count($result_plan_id) > 0) { foreach($result_plan_id as $row) { $get_sponsor_id_1 = $row['sponsor_id']; $get_plan_id_1 = $row['plan_id']; } if($get_plan_id_1 == $my_plan_id) { echo 'Plan id matches.'; } else { $find_plan_id_2 = $db->prepare("SELECT sponsor_id, plan_id FROM records WHERE user_id = :user_id"); $find_plan_id_2->bindParam(':user_id', $get_sponsor_id_1); $find_plan_id_2->execute(); $result_plan_id_2 = $find_plan_id_2->fetchAll(PDO::FETCH_ASSOC); if(count($result_plan_id_2) > 0) { foreach($result_plan_id_2 as $row) { $get_sponsor_id_2 = $row['sponsor_id']; $get_plan_id_2 = $row['plan_id']; } if($get_plan_id_2 == $my_plan_id) { echo 'Plan id matches.'; } else { // repeat the process } } } }
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.