Jump to content

mikenl

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mikenl's Achievements

Member

Member (2/5)

0

Reputation

  1. Is there anyone on phpfreaks that can solve this?
  2. print_r of $_POST (previous post has a o in it...): [lang] => Array ( [0] => 1 [1] => 2 [2] => 58 )
  3. print_r of db query result: [lang1] => 1 [lang2] => 1 [lang3] => 0 [lang4] => 0 [lang5] => 0 [lang6] => 0 [lang7] => 0 [lang8] => 0 [lang9] => 0 [lang10] => 0 [lang11] => 0 [lang12] => 0 [lang13] => 0 [lang14] => 0 [lang15] => 0 [lang16] => 0 [lang17] => 0 [lang18] => 0 [lang19] => 0 [lang20] => 0 [lang21] => 0 [lang22] => 0 [lang23] => 0 [lang24] => 0 [lang25] => 0 [lang26] => 0 [lang27] => 0 [lang28] => 0 [lang29] => 0 [lang30] => 0 [lang31] => 0 [lang32] => 0 [lang33] => 0 [lang34] => 0 [lang35] => 0 [lang36] => 0 [lang37] => 0 [lang38] => 0 [lang39] => 0 [lang40] => 0 [lang41] => 0 [lang42] => 0 [lang43] => 0 [lang44] => 0 [lang45] => 0 [lang46] => 0 [lang47] => 0 [lang48] => 0 [lang49] => 0 [lang50] => 0 [lang51] => 0 [lang52] => 0 [lang53] => 0 [lang54] => 0 [lang55] => 0 [lang56] => 0 [lang57] => 0 [lang58] => 1
  4. yes here's a print_f of $_POST: [lang] => Array ( [0] => 1 [1] => 2 [2] => 58 ) boc 1, 2 and 58 are checked...
  5. Hi, I generate a list of checkboxes like this: // here I set an array, $rows is db query result $language = array(1 => "Afrikaans","Albanian","Arabic","Armenian","Bangla","Bosnian","Bulgarian","Burmese","Catalan","Cebuano","Chinese","Croatian","Czech","Danish","Dutch","English","Esperanto","Estonian","Finnish","French","Gaelic","German","Greek","Hebrew","Hindi","Hungarian","Icelandic","Indonesian","Italian","Japanese","Korean","Kurdish","Latin","Latvian","Lithuanian","Luxembourgish","Macedonian","Malay","Norwegian","Persian","Polish","Portuguese","Romanian","Romansh","Russian","Serbian","Sign Language","Slovak","Slovenian","Sorbian","Spanish","Swedish","Swiss German","Tagalog","Thai","Turkish","Ukrainian","Welsh"); loadform2($language,$rows,'lang'); // here I create the checkbox list function loadform2($values,$rows,$fieldname){ if($_POST){ $output = $_POST; } else { $output = $rows; } $size = count($values); ?> <div style="width:125px;height:100px;overflow:auto;margin-bottom:7px; padding:0"> <? foreach ($values as $key => $value){ if(!empty($key)){ echo "<input id=\"$fieldname".$key."\" name=\"$fieldname"."[]"."\" type=\"checkbox\" value=\"$key\""; if($_POST){ // how do I make this work? $output is $_POST data if ($output[0][$fieldname][$key] == $key-1) echo "checked"; } else { // this works, $output comes from db query if ($output[0][$fieldname.$key] == 1) echo "checked"; } echo "/><label for=\"$fieldname".$key."\">$value</label><br />\n"; } } ?> <input name="<? echo $fieldname ?>_num" type="hidden" value="<? echo $size ?>" /> </div> <? } I want to have all checkboxes that were checked when POSTed to 'stick' but don't know how to do this for $_POST data... Anyone knows how to handle this?
  6. Hi, I have a checkbox array that I use to update a table row. Checkboxes look like: name=lang[] value=1 name=lang[] value=2 (etc) Table row looks like: id, someid lang1, 0 lang2, 1 lang3, 0 lang4, 0 lang5, 1 (etc) MySQL query create by code should be: UPDATE language SET lang1 = '1', lang2 = '1', lang3 = '0' (etc) WHERE id = 'someid' My code: $language = $_POST['lang']; // this is the checkbox array $setlanguage = "UPDATE prof_language SET "; foreach ($language as $key => $value){ if(!empty($key)){ $setlanguage = $setlanguage. ", "; } if($value){ $setlanguage = $setlanguage. "lang".$key." = '1'"; } else { $setlanguage = $setlanguage. "lang".$key." = '0'"; } } $setlanguage = $setlanguage. " WHERE unid = '$session_id'"; mysql_query($setlanguage); I have played with this for days but I can't get it to work. I need to update the row with new '1's and '0's...
  7. OK, messed around with the query, and this is now working: dbsystem(); $setlanguage = "UPDATE prof_language SET "; foreach ($language as $lang => $value){ if(!empty($language)){ $setlanguage = $setlanguage. ", "; } $setlanguage = $setlanguage. "lang".$value." = '$lang'"; } $setlanguage = $setlanguage. " WHERE unid = '$session_id'"; mysql_query($setlanguage);
  8. OK, brainwave: foreach ($values as $key => $value){ if(!empty($key)){ echo "<input name=\"$fieldname"."[]"."\" type=\"checkbox\" value=\"$key\""; if ($rows[0][$fieldname.$key] == 1) echo "checked"; echo "/>$values[$key]<br />"; } } This populates the scrollable checkboxlist with the values from $values (countrynames) and checks the ones that are stored in the db ($rows). I hope someone can use this
  9. Can anyone help me with the problem of how to retrieve rows from a db and set them as selected? I have been trying for the last 2 days and cannot get it to work I guess for an experienced coder this must be a piece of cake?
  10. hmmmm... obviously I'm not good with arrays, but it works I added [$fieldname] to get the values from that row in the db for that select menu. Does this help?
  11. there are only 2 arrays: $values and $rows. $rows I get by left joining a table. $values is set in the HTML as an array. I have a similar function for select menus that aren't using this left joined table: function loadform($values,$session_profset,$rows,$fieldname){ foreach ($values as $key => $value){ echo "<option value='". sprintf("%1d",$key) ."'"; if ($key==$rows[0][$fieldname]) echo " selected=\"selected\""; echo ">$values[$key]</option>\n"; } } This works perfectly. It shows a list of country names (from $values), with the ones coming from the db query ($rows) selected.
  12. I tried to play with the $key and when I use this...: if ($rows[0][$key][$fieldname].$key == 1) echo " <option>++++++testing++++++</option>"; ...it shows me ++++++testing++++++ on the first place in the menu, with 3 leading to 3rd place etc... ???
  13. apparently selected="selected" is the proper HTML. I can change it to SELECTED but it doesn't make a difference... the problem must be in how the $rows values are handled
×
×
  • 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.