Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. Corbin explained it pretty well, but I often find it really hard to judge the price of a project. Especially on larger projects; I've had situations where the person I was working for had an elaborate project overview but I completely under estimated the amount of work that was actually involved. And since I was already locked in on a price I was over-worked. This project doesn't sound especially large, but just a warning, be careful and make sure you're not under estimating the amount of work that needs to be done.
  2. Do you mean you're checking all the elements of more than one array? Can you explain a bit better please.
  3. If you were doing str_replace you'd do something like this: $text = str_replace(Array('[b]', '[/b]'), Array('<b>', '</b>'), $text); Now say if someone entered this text: [b]Hello world There would be no closing </b> tag, which can cause problems (be it display problems or validation issues).
  4. Sure, you can use str_replace, or even better would be preg_replace()
  5. He means: $theStyle = <<<HERE "border-width:$borderSize $sizeType; border-style: $borderStyle; border-color: green" HERE; should be: $theStyle = <<<HERE "border-width:$borderSize $sizeType; border-style: $borderStyle; border-color: green" HERE;
  6. Negative numbers? Give an example, do you mean like: negative numbers within the string, or a negative over all?
  7. Are you only checking one variable? Because that's what it sounds like from that description. Because you want to know the index of the element if you should use a for(): for($i = 0;$i < count($arr);$i++) { echo $arr[$i]; }
  8. You can do this with JavaScript, however a better alternative would be to alter what you have on the receiving php file. Instead of like: $user = $_POST['user']; make it: $user = $_POST['user'] . '@yahoo.com';
  9. Nested foreach loops: foreach($arr1 as $part1) { foreach($arr2 as $part2) { //Stuff } }
  10. && would probably be better to use otherwise something that's like 9X100 would get deleted which isn't what the OP wanted (at least from what I can tell).
  11. No problem, just remember to press the "Topic Solved" button at the bottom left of the topic, and in the future.
  12. Just use microtime() For this specific case I did this: <?php $start = microtime(true); for($i = 0;$i < 1000000;$i++) if($paged == 0 || $paged == "") { $paged = 1; } echo (microtime(true) - $start);
  13. I'd do: $paged = (empty($paged) || $paged == 0) ? 1 : $paged; Ultimately your normal if statement would be the fastest, but that shouldn't matter because even ran through 1,000,000 times the difference in negligible (around 0.01 - 0.1 second(s)). The most important thing in cases like this is that it's easiest to read.
  14. So what do you get as output when you run this? public function add($users, $stream_users, $config) { $login = $config->get_username(); $password = $config->get_password(); $listid = $config->get_listid(); $add_list = NULL; $request = NULL; /*checks to see if any users need to be added to the list*/ $r = 0; foreach($users as $user) { $Add_this_user = TRUE; foreach($stream_users as $stream_user) { $todays_date = date("Y-m-d G"); if(($user[1] == $stream_user[4]) && ($stream_user[3] == 'active')) { if(((preg_match('/A/', $user[8])) == 0) || ($user[9] < $todays_date) || ($user[7] == 1) || ($user[5] == 0) || ($user[6] == 0) || ($user[10] == 1)) { $Add_this_user = FALSE; } } $Add_this_user = FALSE; echo "Add_this_user is FALSE"; } if($Add_this_user) { if($user[1] != NULL) { $add_list[$r][1] = " <parameter id='{emailaddress}'><value>".$user[1]."</value></parameter>"; } if($user[2] != NULL) { $add_list[$r][2] = " <parameter id='{firstname}'><value>".$user[2]."</value></parameter>"; } if($user[3] != NULL) { $add_list[$r][3] = " <parameter id='{lastname}'><value>".$user[3]."</value></parameter>"; } if($user[4] != NULL) { $add_list[$r][4] = " <parameter id='{title}'><value>".$user[4]."</value></parameter>"; } $r++; } } if($add_list != NULL) { // Build the XML for the Request(s) $b = 0; foreach($add_list as $user) { $request[$b] = "<system>". "<action>addsubscriber</action>". "<authorization>". "<username>".$login."</username>". "<password>".$password."</password>". "</authorization>". "<parameterlist>". "<parameter id='List ID'><value>$listid</value></parameter>". "[<parameter id='Auto-Activate'><value>true</value></parameter>]". "<parameterarr>"; foreach($user as $attribute) { $request[$b] .= $attribute; } $request[$b] .= "</parameterarr>". "</parameterlist>". "</system>"; $b++; } } else{$request = NULL;} return $this->_xml = $request; }
  15. The only reason that I can think of is a situation where $stream_users has no elements so that foreach loop isn't preformed at all. For debugging I'd suggest placing an echo statement right after or before $Add_this_user is set to false within the foreach statement to see if it's even being executed. That or just print_r (or var_dump()) $stream_users to confirm that it has contents.
  16. I don't know your specific situation so it's hard to give you advice. You could be going in a completely wrong way and I wouldn't know because I don't know what you're trying to accomplish. From the given information it seems like you'd be best off doing something like: session_start(); //Query stuff $_SESSION['result'] = Array(); while($row = mysql_fetch_assoc($result)) $_SESSION['result'][] = $row;
  17. You can do force downloading with PHP like mikesta707 stated, but you can also do it with .htaccess: <Files *.jpg> ForceType application/octet-stream Header set Content-Disposition attachment </Files>
  18. The problem with this is that once the script stops executing the mysql connection is closed and those mysql resources will no longer be valid. Explain your situation better and we can help you find an alternative.
  19. What browser are you using? Because I know that IE has problems with UTF-8.
  20. My example was just to give you an idea, not to actually use. If you want a more detailed explanation / example just ask.
  21. Use UTF-8: <?php header("Content-type: text/html; charset=UTF-8"); print("string(".strlen($_GET['var']) .") ".$_GET['var'] ."\n"); print(urldecode($_SERVER['REQUEST_URI'])); ?>
  22. Sorry. session_start(); foreach($_POST['option'] as $option) { $values = explode(',', $option); $_SESSION['prices'][] = $values[1]; $_SESSION['items'][] = $values[0]; } echo array_sum($_SESSION['prices']); // Total Btw, you can't have any output before session_start() or you'll get a headers already sent error.
  23. I edited my code for a small error (If you look at your quote you even quoted the fixed code).
  24. He had a small typo, fix: <?php //Create an array of the valid options $all_ranks = range(1, 10); //Create new array and fill with used ranks $used_ranks = array(); foreach ($find as $record) { if (!in_array($record['rank'], $used_ranks)) { $used_ranks[] = $record['rank']; } } //Get the diffrence of $all_ranks and $used_ranks (i.e. the unused ranks) $unused_ranks = array_diff($all_ranks, $used_ranks); //Create the options for select list $unused_rank_options = ''; foreach ($unused_ranks as $rank) { $unused_rank_options .= "<option value="{$rank}">{$rank}</option> " } ?> Rank: <select name="rank"> <?php echo $unused_rank_options; ?> </select>
  25. What would the options be check boxes? If that's possible for what you're wanting to do that's what I'd do because you could do it like this: <input type="checkbox" name="option[]" value="paint,250" /> <input type="checkbox" name="option[]" value="something,200" /> session_start(); foreach($_POST['option'] as $option) { $values = explode(',' $option); $_SESSION['prices'][] = $values[1]; $_SESSION['items'][] = $values[0]; } echo array_sum($_SESSION['prices']); // Total
×
×
  • 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.