PHP For Each loop with radio buttons as results


PHP For Each loop with radio buttons as results



( Just FYI this function is being used on a Wordpress website in my custom plugin )



This function is supposed to display results as radio buttons based on certain parameters. My problem is, I'm not sure how to insert my ID into a radio button. And I'm not sure how to get multiple radio buttons based on the amount of results I get. There should be one radio button per result.



To put this situation into context, this is for an (RPG) Role Playing Game similar to "World of Warcraft", or "EverQuest". A user makes a character by entering a name, race and class into a form. This data is inserted into my database table called "wp_ml_character". On a separate page, this function "ml_skill_select" is called, and is supposed to display all of the user's characters and then display skills to choose from based on the user's selection.



Here's how It's supposed to work:



It's almost like doing a search and getting results, but it's using radio buttons as options instead of being able to type something in a search box.



Here's my function as of right now. The part I'm stuck on is my HTML form which holds the radio buttons on lines 200 to 212.


function ml_skill_select() {
?>
<form action="#ml_skill_form" method="post" id="ml_skill_form">
<?php

$umid = um_profile_id();
global $wpdb;
$char_select = $wpdb->get_results ( "
SELECT fname, class_id
FROM wp_ml_character
WHERE um_id = $umid
" );
foreach ( $char_select as $result ) {
?>
<input type="radio" name="character" value="<?php $result->class_id ?>"/><?php echo $result->fname; ?><br>
<?php
}
?>

<input type="submit" name="submit_form" value="submit" />
</form>
<?php

if ( isset( $_POST["submit_form"] ) && $_POST["character"]){
$skill_select = $wpdb->get_results ("
SELECT * FROM wp_ml_skills
WHERE class_id = $result
");
}
}



enter image description here



Any suggestions would be greatly appreciated, thanks in advance!





Add your code instead of an image
– user3284463
Jun 30 at 20:02





Please do not use images of your code, copy/paste the text into your question and use the code sample formatting button. As for the immediate issue in your code, you excluded the echo , it should be <?php echo $result->class_id; ?>
– fyrye
Jun 30 at 20:02


code sample


echo


<?php echo $result->class_id; ?>





I'll try, it. But it was having issues displaying in the "code" block before which is why I used an image.
– Cody Tetreault
Jun 30 at 20:03





Ok, I see, I'll try adding the echo right now.
– Cody Tetreault
Jun 30 at 20:09





@fyrye This worked perfectly when I added the echo. Thank you. Now, each radio button has a name displayed next to it. Before, nothing showed up.
– Cody Tetreault
Jun 30 at 20:19









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

Decreasing a static image progress bar horizontally in SDL

C++ thread error: no type named ‘type’ MINGW