Jump to content

[SOLVED] Using Yes/No <Input> with a Dynamic Recordset problem?


A JM

Recommended Posts

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,

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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++;
}

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

$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';
}

 

 

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.