/    Sign up×
Community /Pin to ProfileBookmark

Php recordset outputting last value from while loop

Hi all,

I have an issue with a site I am making which lists radio buttons which are a set of donation options (some with predefined prices some with user dependant).

I used jQuery to populate a textbox with the value of the radio buttons so the person does not need to enter a price they want to donate.

The issue I am having is that I want the page to carry across the fund_id (which is the primary key) to the next page.

Currently the do / while loop goes through all of the recordset and passes across the last record’s fund_id.

Please see my code below:

[CODE] $(function () {

$(‘input.radioButton’).click(function () {

var checkedradio = $(‘[name=”fund”]:radio:checked’).val();

$(‘#totalPrice’).val(checkedradio);

});

});[/CODE]

And

[CODE]
<form action=”donate2.php” method=”post” name=”donateFormScript”>
<h1>Select Fund</h1>
<h3>General</h3>
<?php do { ?>
<label><input class=”radioButton” type=”radio” name=”fund” value=”<?php echo $row_cat_general[‘fund_price’]; ?>” id=”<?php echo $row_cat_general[‘fund_name’]; ?>” /><?php echo $row_cat_general[‘fund_name’]; ?> <?php if ($row_cat_general[‘fund_price’]!=””) { ?>- &pound;<?php echo $row_cat_general[‘fund_price’]; ?><?php } else {?> <?php };?></label>

<br />
<?php } while ($row_cat_general = mysql_fetch_assoc($cat_general)); ?>

<h3>Sponsorship</h3>
<?php do { ?>
<label><input class=”radioButton” type=”radio” name=”fund” value=”<?php echo $row_cat_sponsorship[‘fund_price’]; ?>” /><?php echo $row_cat_sponsorship[‘fund_name’]; ?> <?php if ($row_cat_sponsorship[‘fund_price’]!=””) { ?>- &pound;<?php echo $row_cat_sponsorship[‘fund_price’]; ?><?php } else {?> <?php };?></label>
<br />
<?php } while ($row_cat_sponsorship = mysql_fetch_assoc($cat_sponsorship)); ?>

<h3>Seasonal</h3>
<?php do { ?>
<label><input class=”radioButton” type=”radio” name=”fund” value=”<?php echo $row_cat_seasonal[‘fund_price’]; ?>” /><?php echo $row_cat_seasonal[‘fund_name’]; ?> <?php if ($row_cat_seasonal[‘fund_price’]!=””) { ?>- &pound;<?php echo $row_cat_seasonal[‘fund_price’]; ?><?php } else {?> <?php };?></label>
<br />
<?php } while ($row_cat_seasonal = mysql_fetch_assoc($cat_seasonal)); ?>
<br />
<span id=”sprytextfield1″>
<label>Enter Amount:
<input name=”total” type=”text” id=”totalPrice” />
</label>
<span class=”textfieldRequiredMsg”>A donation amount is required.</span></span><br />
<input name=”fund_id” type=”hidden” value=”<?php echo $row_cat_general[‘fund_id’]; ?>” id=”fund_id” />
<input name=”button” type=”submit” value=”Select” />

</form>
[/CODE]

I hope this doesnt look weird, once I have post this.

Is there a way I can populate “totalPrice” input box AND have “fund_id” hidden field populated with the fund_id of the selected radio button?

Thanks for your help.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@firesnakerJan 06.2013 — Pass the fund_id to a hidden input on the form for each radio box. Then get and set the value together with the jQuery function for the radio box.
Copy linkTweet thisAlerts:
@catalepticstateauthorJan 06.2013 — I'm not sure how to do that with jQuery.

I have no experience with jQuery.
Copy linkTweet thisAlerts:
@catalepticstateauthorJan 06.2013 — Hi,

I tried to make your suggestion work but it still outputs the last record in the table.

Thanks
Copy linkTweet thisAlerts:
@catalepticstateauthorJan 07.2013 — Can anyone help?
Copy linkTweet thisAlerts:
@catalepticstateauthorJan 09.2013 — Does anyone know of any good donation scripts that have multiple donatable causes?
×

Success!

Help @catalepticstate spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...