Jump to content

bluegray

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bluegray's Achievements

Member

Member (2/5)

0

Reputation

  1. Yes the values come from a Database query. Why, what are your thoughts?
  2. Okay, so here's my goal. I need to make sure a foreign country portion of the page is not displaying if there are no foreign countries (native country being U.S.) in the array. here's an example of the $country array on a dump: array(4) { [0]=> string(2) "US" [1]=> string(2) "US" [2]=> string(2) "US" } So naturally I don't want the "Foreign" country section to display if there are no foreign countries. However, there are alternatively some 40+ other country names to check for so I need a solution that scans for anything that's not the U.S. and then returns a true/false.
  3. Then I would have to do in_array once for every other kind of country there is. Not Very Efficient. Maybe it can be done with in_array but you need to specify how because the how is where I'm stuck.
  4. Forgive my brevity, I'm short on time, and don't exactly know how to articulate this question. So I'm going to have an array with different country names in it. Call it $country []. Now I need to check the array for any non-U.S. country. The array will always have at least 1 U.S. in it, but I need to know how to check for true/false the presence of there also being something else like UK, MX, AU, etc. Do I need to specify anything else? Please help me, PHP addicts .
  5. Simply saying extract () gets the same effect doesn't provide much in terms of context to try it out with. When you say "this" in "If you're using this..." what is "this?" Then, what are register_globals, and why are they a security risk? If that's all in reference to the earlier mentioned extract (), are you saying I shouldn't use it? Why mention it if it's so risky?
  6. Hey Ken, So I tried this in the main file and it worked. But when I tried to implement the foreach () loop in a function the variables weren't being recognized. I kept getting an undefined variable error. Do you know how I would alter the code you provided so it works from a user defined function?
  7. Hello! So I make myself an array by writing: $input = $_POST['create'] ; and on a var_dump() the array looks something like: array(6) { ["account"]=> string(7) "woo hoo" ["pass"]=> string( "security" ["pass2"]=> string( "security" ["name_first"]=> string(3) "Dan" ["name_last"]=> string(5) "Tayle" ["Email"]=> string(14) "snotme@him.com" } Okay so to the point. I need to assign these values to variables by the names of the keys. What I've tried so far has failed, and here it is: function inputis ($data) { if(!isset($data)) { $input = array(); } else { $input = isset($data)?$data:null ; $tmp = array(); foreach ($input as $k => $v) { $tmp[] = "$". $k . ' = ' . "'" . $v . "'" ; } $results = $tmp ; return $results ; } } The var_dump() there looks like what I need, it doesn't seem to actually assign the variables. What's the best thing to do from here?
  8. Hi Php freaks, So I'm pulling an array from a $_POST, and in it I have its keys and values. Take this example: "1" => "a" "2" => "b" "3" => "c" Now, if I can separate the keys and the values into their own arrays, what I need to do is interweave them into a string where all keys are matched up to their values like such: <string> 1 = "a", 2 = "b", 3 = "c" </string> I'm trying to build a function that does, this and here's what it looks like so far: if(!isset($data)) { $boxdata = array(); } else { $boxdata = isset($data)?$data:null ; //var_dump($boxdata) ; foreach ($boxdata as $bd) { $keys = array_keys($boxdata); } I figured it would be simplest to build the string from the foreach () loop, but don't know how to do it, or if there are better ways. Ideas please?
  9. A new problem came up. Apparently, when I don't check any of the boxes, I get this funky message: NULL Notice: Undefined variable: keys in C:\wamp\www\test\functions.inc.php on line 38 NULL Notice: Undefined variable: keys in C:\wamp\www\test\functions.inc.php on line 39 Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\test\functions.inc.php on line 39 What should I do to counteract it? Because if I check at least one, everything moves as expected.
  10. mjdamato I used the array_keys function which worked well, but what confused me is how that same function I used worked exactly as intended with a text type input. With virtually the same format, barring the word "checkbox" in the type attribute, it changed the results. Also, I mainly used the names of the element as it differs from the value because of the separation between fields and values in the query. But furthermore, and perhaps more importantly, I'm mostly just doing function testing with largely arbitrary values so I can get a feel for how things work. I want to make a function that takes a variety of forms and processes them without having to manually write the database queries.
  11. I'm trying to build a function that processes the (x)html checkbox. I'm stuck at trying to extract the keys from the array that makes it through the form. Here is the full function so far: $boxdata = isset($data)?$data:null ; var_dump($boxdata) ; foreach ($boxdata as $bd) { $key = key ($boxdata) ; $keys[] = $key ; next ($boxdata) ; } var_dump ($keys); $fields = implode (', ', $keys) ; //return $fields ; echo "<p>$fields</p>" ; Now, when I var_dump $boxdata, I get the full 4 value array. When I var_dump $keys I get a 4 value array that's been shifted. The first value from $boxdata is missing, and the 4th value is suddenly null. So by the time I echo "$fields" I'm missing the first element in the $boxdata array. The most irritating part is this function worked when dealing with "text" type inputs, but the "checkbox" just keeps trying to kick me down. What...the heck? Thanks for your help Php Freaks.
  12. Sweet stuff. Okay... I used the shorter version because as you said, it's neater. I'm still having some issues with the nature of checks though. How would you handle processing them into an SQL database when they're part of a larger form? The problem is that when, say 5 out of 10 boxes are checked, the array that's filled only has 5 elements; whereas if it was a text type input the array would have 10 elements with 5 nulls. Right now, it seems the best plan is to sort them into a separate array from text type inputs, with an argument representing the number of values that Could be received, and have a custom function fill all the empties with a null.
  13. Perhaps I asked my question incorrectly. I understand how the code functions, but I've never seen the "?" or ":" defined or even used before. What's the purpose of the if, else statement if we have "?" and ":" to use. Additionally, I've learned whatever I know from Php books, yet have never seen these two operators offered as an alternative to the "if else" statement. Is there a reason for this?
×
×
  • 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.