Jump to content

Omzy

Members
  • Posts

    314
  • Joined

  • Last visited

    Never

Everything posted by Omzy

  1. Omzy

    PHP Division

    Yes I want it divided by two. If the result is not a whole number then it should round up to the next whole number.
  2. I need an IF statement that will round UP as follows: 50 / 2 = 25 49 / 2 = 25 But obviously must work for all numbers. ($i / 2 = $x)
  3. I find myself doing this a lot of the time: if(isset($_POST['name'])) $name=$_POST['name']; I get the feeling there is a simpler way of doing this. It's not such a bother if it's just one or two but its when you have a whole bunch of these that it gets tedious!
  4. This is how I managed to do it in the end: function proptypeBoxes(index) { var type_checkboxes = document.getElementsByName("prop_type[]"); for (var i = 0; i < type_checkboxes.length; i++) { if(index.value!='') { document.getElementById('all_types').checked = false; } else if(index.value=='') { type_checkboxes[i].checked = false; } } } <input type="checkbox" name="" value="" id="all_types" onclick="proptypeBoxes(this)" />All types <input type="checkbox" name="prop_type[]" value="type1" onclick="proptypeBoxes(this)" />Type 1 <input type="checkbox" name="prop_type[]" value="type2" onclick="proptypeBoxes(this)" />Type 2 Works exactly how I want it to.
  5. Ok cool I get it. Just a quick question - if I don't give the "check_all" checkbox a name attribute then does it still append to the GET query string? I noticed some empty variables in my query string.
  6. Well If I don't give the "check all" checkbox a name then I should be able to group all the other checkboxes by using something like getElementsByName()? Do you know how I could implement this (using your sample solution)?
  7. Cheers DJ Kat. I forgot to mention though that all checkboxes need to share the same NAME attribute. That's probably the biggest difficulty in what I'm trying to achieve.
  8. That's exactly what I'm trying to acheive.
  9. Well the user needs to be able to select multiple checkboxes.
  10. Can anyone provide a simple function or even inline solution to this.
  11. roopurt18 - no that's not true. besides you can't include query parameter's in the form's ACTION attribute. I think I'm just gonna combine both forms in to one, as has been suggested.
  12. I'm looking for a simpler solution (not using JQuery).
  13. I got 3 checkboxes: 1) All Types 2) Type 1 3) Type 2 If Type 1 or Type 2 is ticked then All Types should get unticked (if it is ticked) If All Types is ticked then all other boxes should get unticked (if they are ticked) Can someone provide a basic solution to acheive this functionality?
  14. Actually this won't work when JavaScript is disabled, so is there any other method?
  15. I see. So it's more to do with the way the browser displays the URL rather than how it processes the request.
  16. This isn't strictly PHP, but perhaps there is a PHP function that might help with this.. On a GET form submission, IE seems to output the page URL with certain characters encoded to their ASCII equivalent, for example if you have a group of checkboxes as an array (name="location[]"). In IE it's output in the address bar as: search.php?location%5B%5D=whatever In Firefox/Chrome it's output as it should be (search.php?location[]=whatever) For the sake of consistency and neater looking URLs, how can I fix this issue in IE? I tried the urldecode() function on the form action but that didn't work. Anything to do with the enctype attribute on the form?
  17. Well there are more forms within the body of the document.
  18. It's an estate agent site - one form is at the top and specifies the sort order and how many results per page, the other form is at the side and lets you refine the property features. Naturally you'd want to retain one form's options when the other form is submitted.
  19. Basically I have two forms on the page, both forms use GET method and have an ID attribute. I want the data from both forms to be included in the form submission whenever either of these forms are submitted.
  20. That didn't work either. I figured it out myself: echo '<option value="'.$index1.'"', in_array($index1, explode(', ', $value)) ? ' selected="selected"' : null ,'>'.$value1[1].'</option>';
  21. No, that isn't quite right. Firstly I don't need to use array_keys() because I'm already getting the keys from my FOREACH loop. And secondly shouldn't the implode() function be run on the $csv?
  22. Can anyone help please? To make it easier to understand: $csv="flowers, balloons, banners"; Compare $csv to array indexes of $subcats, echo out the index if true
  23. Basically I'm reading data from a MySQL database, and I want to compare this data to an array. The array is called $subcats and has the following sample data: $subcats=array( 'flowers'=>array('decorations', 'Flowers'), 'balloons'=>array('decorations', 'Balloons'), 'banners'=>array('decorations', 'Banners'), 'fruit-displays'=>array('decorations', 'Fruit Displays'), 'ice-sculptures'=>array('decorations', 'Ice Sculptures'), ); The data I wish to compare against is in a field called 'tags', which contains a string of values separated by a comma, for example: flowers, balloons, banners Now what I want to do is print out a SELECT MULTIPLE control which has the relevant options selected if they exist in that field. Here is the code I have so far (simplified): foreach($row as $key => $value) { echo '<select size="5" name="'.$key.'">'; foreach($subcats as $index1 => $value1) { echo '<option value="'.$index1.'"', $index1==$value ? ' selected="selected"' : null ,'>'.$value1[1].'</option>'; } echo '</select>'; } Now obviously the $index1==$value part is incorrect, and I'm a bit unsure what should be used to do the comparison. Can anyone help?
×
×
  • 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.