A JM Posted June 16, 2009 Share Posted June 16, 2009 I'm running into a slight problem getting a Yes/No <input> to work with a dynamic recordset. Creating the Yes/No options aren't the problem, its that each record when I choose either Yes or No impacts the other records on my form in a different record. For example, on record 1 if I choose Yes or No choosing one deselects the other but if I move to record 2 and do the same then record 1 clears and vice versa. How do I get this to work since I think I have to name the input type the same name in order to get the Yes/No to originally work? <input type="radio" name="chk_accept[]" value=1> <input type="radio" name="chk_accept[]" value=0> A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/ Share on other sites More sharing options...
Zane Posted June 16, 2009 Share Posted June 16, 2009 yeah they can't ALL be named chk_accept[] you need them like Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856970 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 I thought that might be the problem but am not sure how to create the auto numbering, any suggestions on how to do that? A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856978 Share on other sites More sharing options...
Zane Posted June 16, 2009 Share Posted June 16, 2009 with PHP for($i=0; $i echo '\n'; echo '\n'; } That would create 50 sets of Yes No radio buttons.....that work. Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856979 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 The recordset is dynamic so a set nnumber ofiterations won't get it... I had used this routine on a dropdown box that worked great but wasn't sure how to implement for my <input> items? $theusers = ''; $theusers .= '<select name="adj[]"><option value="Please Select">Please Select</option>'; while ($row = mysql_fetch_assoc($rst_adjusters)) { $theusers .= '<option value=' . $row['ID'] . '>' . $row['firstname'] . ' ' . $row['lastname'] . '</option>'; } $theusers .= '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856982 Share on other sites More sharing options...
joel24 Posted June 16, 2009 Share Posted June 16, 2009 what do you mean dynamic? like the amount of radio groups is dependent on the number of database rows...? Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856984 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 yes, that is corect. I was trying something like this but can't get it to work. //<Input type=radio $theusers = ''; $theusers .= '<input type="radio" name="chk_accept[]"'; while ($row = mysql_fetch_assoc($rst_adjusters)) { $i=0; $theusers .= . $i . ; $i++; } $theusers .= 'value=1>'; Then on the form: <?php echo $theusers; ?> [edit] <input type="radio" name="chk_accept[]"012345678 value=1> It's close but I think it needs to be in the form loop. Can I set up a counter in the form? Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856990 Share on other sites More sharing options...
joel24 Posted June 16, 2009 Share Posted June 16, 2009 are you actually pulling any data from the database with your the sql command.. the $rst_adjusters one? or just counting how many rows?? anyway, the code you had would add $i to the end of the input tag... well fater teh chk_accept thingo however many times the loop exectured.. i.e. '<input type="radio" name="chk_accept[]"123456789101112value=1>... and having $i=0 at the top of the loop, $i will always equal zero, you need it before the loop. you need to echo the input statement within the loop i.e. $i = 0; while ($row = mysql_fetch_assoc($rst_adjusters)) { echo '<input type="radio" name="chk_accept{$i}[]" value=1>\n'; echo '<input type="radio" name="chk_accept{$i}[]" value=0>\n'; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856992 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 I'm just trying to loop through the number of records in the recordset. Can I implement a counter in the form, how would I do that? Like: <?php $counter++><input type="radio" name="chk_accept[]" . <?php $counter> . "value=0> Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-856996 Share on other sites More sharing options...
joel24 Posted June 16, 2009 Share Posted June 16, 2009 $rowCount = mysql_num_rows($rst_adjusters); for ($i = 0; $i <= $rowCount; $i++) { echo '<input type="radio" name="chk_accept{$i}[]" value=1>\n'; echo '<input type="radio" name="chk_accept{$i}[]" value=0>\n'; } will do it, however, you're better off changing your mysql query, so the MySQL db counts... change it to something like $rst_adjusters=@mysql_query("SELECT count(*) FROM tableName WHERE x = y"); and then have $rowCount = mysql_fetch_row($total); $rowCount = $rowCount[0]; for ($i = 0; $i <= $rowCount; $i++) { echo '<input type="radio" name="chk_accept{$i}[]" value=1>\n'; echo '<input type="radio" name="chk_accept{$i}[]" value=0>\n'; } Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857005 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 thanks joel24. I think I may have found the solution and it appears easier than I thought... <input type="radio" name="chk_accept<?php echo $i++; ?>[]" value=1> Do you see a reason why this wouldn't work? :-\ A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857008 Share on other sites More sharing options...
Adam Posted June 16, 2009 Share Posted June 16, 2009 Yes/No values are surely better achieved with a checkbox for each record instead? Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857015 Share on other sites More sharing options...
joel24 Posted June 16, 2009 Share Posted June 16, 2009 $i++ means that the variable $i will increment by one each time the loop or script reaches it... the line <input type="radio" name="chk_accept<?php echo $i++; ?>[]" value=1> alone would just echo the value of $i + 1 once. i.e. say $i is equal to 1 it would only echo the following line. <input type="radio" name="chk_accept2[]" value=1> you need a loop to echo it multiple times... like the for loop or while loop i showed u Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857016 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 Correct Joel. In the form there is a loop, the Dynamic table was created by Dreamweaver CS4. Now that I see how this is working I needed to create the variables as you said and add my object, it works as needed. <?php do { ?> ... <?php } while ($row_rstassign = mysql_fetch_assoc($rstassign)); ?> Thanks for your help - you got me there. Yes/No values are surely better achieved with a checkbox for each record instead? I agree and will be changing them. Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857020 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 Since I'm new here - do I need to close this question or wrap it up somehow? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857025 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 Yes/No values are surely better achieved with a checkbox for each record instead? How do I get a checkbox to uncheck when I select the opposite item? its not performing like a radio button... A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857029 Share on other sites More sharing options...
Adam Posted June 16, 2009 Share Posted June 16, 2009 If you're grouping 2 radio inputs together with a value of 'Yes' for one and 'No' for the other, well then that could be done with just one checkbox? Then you can check / uncheck other with Javascript. Hmm perhaps I didn't have a clear picture of what you were trying to do? Oh and if you're question gets solved just mark it as solved.. Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857033 Share on other sites More sharing options...
A JM Posted June 16, 2009 Author Share Posted June 16, 2009 I was thinking 2 checkboxes... duh. I got you now. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/162367-solved-using-yesno-with-a-dynamic-recordset-problem/#findComment-857154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.