I have a series of categories related to hotel services and each category has a selection of checkbox’s for instance the ‘Rooms’ section has air conditioning, balcony, bathrobes, bathtub, beach view and so on, there loads of them and these are for the admin guys here to fill in as we put hotels into the db.
After selecting they click ‘submit’ and these selections are stored in an array and entered into their sections in the db, that bit is fine, its when the page returns I need those checkbox’s to still be checked to confirm everything.
So below is the what creates the checkbox’s for one section as the page loads -
$q=mysql_query(" select Id_HnS, Id_Stand from tbl_hotnstand where Id_Hot=$germanID");
while($r=mysql_fetch_row($q)){ $standards[$r[1]]['selected']=1; }
$q=mysql_query(" select Id_HnA, Id_Ame from tbl_hotname where Id_Hot=$germanID AND ((Id_Ame > 0) && (Id_Ame < 201))");
while($r=mysql_fetch_row($q)){ $Gamenities[$r[1]]['selected']=1; echo $Gamenities[$r[1]]."visit"; }
$q=mysql_query(" select Id_HnA, Id_Ame from tbl_hotname where Id_Hot=$germanID AND ((Id_Ame > 200) && (Id_Ame < 401))");
while($r=mysql_fetch_row($q)){ $Ramenities[$r[1]]['selected']=1; }
$q=mysql_query(" select Id_HnA, Id_Ame from tbl_hotname where Id_Hot=$germanID AND ((Id_Ame > 400) && (Id_Ame < 601))");
while($r=mysql_fetch_row($q)){ $Samenities[$r[1]]['selected']=1; }
$q=mysql_query(" select Id_HnA, Id_Ame from tbl_hotname where Id_Hot=$germanID AND ((Id_Ame > 600) && (Id_Ame < 801))");
while($r=mysql_fetch_row($q)){ $Mamenities[$r[1]]['selected']=1; }
$q=mysql_query(" select Id_HnA, Id_Ame from tbl_hotname where Id_Hot=$germanID AND ((Id_Ame > 800) && (Id_Ame < 1001))");
while($r=mysql_fetch_row($q)){ $Aamenities[$r[1]]['selected']=1; }
$q=mysql_query(" select Id_HnT, Id_Tem from tbl_hotntem where Id_Hot=$germanID");
while($r=mysql_fetch_row($q)){ $thems[$r[1]]['selected']=1; }
$q=mysql_query(" select id_HnT, Id_TOp from tbl_hotntop where Id_Hot=$germanID");
while($r=mysql_fetch_row($q)){ $touroperators[$r[1]]['selected']=1; }
I put an echo in $Gamenities just to check that it was counting the checked boxes, and it’s coming back correct. But then the code below is not reflecting those boxes that are checked.
If you var_dump any of the arrays you created, does it give you what you might expect? And when it’s produced the HTML code, if you do a “view source” in the browser, does that show anything? On the latter point I’m wondering whether the issue is needing to echo " checked" to make sure there’s a space after the name, but it’s a while since I’ve tried it and I can’t remember whether html cares about that.
You get NULL because you’re dumping the array outside your while() loop, and by that time $r has no value (which is how the loop exited). Just dump the whole array
Well, I can’t see it. I manually created an array and copied your code into it to display, and I get three ticked checkboxes. I can only guess it must be something to do with the other code, for example I can’t see where you create the [‘name’] field, or where (if) you build the un-ticked entries. I didn’t need to add a space before “checked”, so that was a red herring.
when the page loads first time so no hotel selected I think it uses the code below to create the checkboxes -
$q=mysql_query('select * from tbl_standards order by Id_Stand');
while($r=mysql_fetch_row($q)) { $standards[$r[0]]=array('id'=>$r[0],'name'=>$r[6], 'selected'=>0 ); }
$q=mysql_query('select * from tbl_amenities WHERE ((Id_Ame > 0) && (Id_Ame < 201)) order by Nom_Ame') or die(mysql_error());
while($r=mysql_fetch_row($q)) { $Gamenities[$r[0]]=array('id'=>$r[0],'name'=>$r[1], 'selected'=>0 ); }
And is all that still present after you’ve done the inserts? When you var_dumped $Gamenities above, it only had the selected entries, or did you edit out the rest for privacy or whatever? And is the id field the same in the array, as you use $r[0] in one and $r[1] in the other, albeit with different queries?
I think I’ve got it, nothing really wrong with the code just that the loading of the checkboxes was being over written due to them being outside an if statement.
I moved them inside, and it seems to have done the trick. But thank you as I wouldn’t have got there unless we had sort of gone through it like we did.