I’d like to use the variable bradio in the “Having” clause of my query but i don’t know how to get the content of the jquery variable and passe it into my sql query. This is a fragment of my php file. Can you tell me how can I do this?
Thanks
$conn = mysql_connect("localhost","form-test","pass");
$db = mysql_select_db("form-test",$conn);
?>
<script type="text/javascript">
jQuery.noConflict();
jQuery(function()
{
jQuery('#event_form_field-<?php echo $event_id; ?>').click(function()
{
var bradio= jQuery("input[type=radio]:checked").val()
alert(bradio); });});
</script>
<?php
$query2 = "SELECT COUNT(wp_events_answer.answer) as rep, wp_events_answer.attendee_id as idq, wp_events_question.quota as quota2, wp_events_attendee.event_id as ev, wp_events_answer.answer as answ, wp_events_question.id as qst3
FROM wp_events_answer, wp_events_attendee, wp_events_question
WHERE wp_events_answer.question_id = wp_events_question.id AND wp_events_answer.attendee_id = wp_events_attendee.id
HAVING answer =
GROUP BY answ;";
$result2 = mysql_query($query2) or die(mysql_error());
while($row2 = mysql_fetch_row($result2)) {
}
?>
You can’t mix both PHP and javascript code in one page using the method above. The problem is because PHP is executed on the server, well before any javascript can be run on the client. Therefore, the two cannot speak to each other.
The solution here is to make an AJAX request to a PHP script on your server and pass the value of the radio control to it. This would then return the required data and you can then use javascript to display this on your page.
For example: