动态单选按钮通过PHP和ajax

时间:2022-03-25 09:23:23
<?php
session_start();
include'session.php';
include'dbconnect.php';

//unset($_SESSION['creatureid']);
$id=$_SESSION['id'];

function char_options() {
$sql="select id,name,type,level from characters where act_id='$_SESSION[id]'";
$sql2=mysql_query($sql);
$s=mysql_fetch_array($sql2);
while($s) {
        echo"<input type='radio' name='char_choice' value='".$s['id']."'>".$s['name']." ". $s['type']." ". $s['level']." ";
    }
}
 ?>


<div id="frm_character_select">
<form action="">
  <?php  char_options(); ?> 
</form> 
</div>

So I am trying to make dynamic radio buttons which show 1 button per character on an account. My problem is that everything below the calling of the function is not loading on the page, and the page seems to load forever. Any pointers on how to fix this?

所以我正在尝试制作动态单选按钮,在帐户上每个字符显示1个按钮。我的问题是,在函数调用之下的所有内容都没有在页面上加载,并且页面似乎永远加载。有关如何解决此问题的任何指示?

P (ajax) : on button (btn_character_selection) click it shows the div (frm_character_select) which has the radio buttons and information. None of the ajax is working either after i added the radio buttons.

P(ajax):在按钮(btn_character_selection)上单击它显示div(frm_character_select),其中包含单选按钮和信息。在添加单选按钮后,ajax都没有工作。

2 个解决方案

#1


0  

Change this

$s=mysql_fetch_array($sql2);
while($s)

to

while($s=mysql_fetch_array($sql2))

#2


0  

Try this

while($s=mysql_fetch_array($sql2)) {
    echo"<input type='radio' name='char_choice' value='".$s['id']."'>".$s['name']." ". $s['type']." ". $s['level']." ";
}

#1


0  

Change this

$s=mysql_fetch_array($sql2);
while($s)

to

while($s=mysql_fetch_array($sql2))

#2


0  

Try this

while($s=mysql_fetch_array($sql2)) {
    echo"<input type='radio' name='char_choice' value='".$s['id']."'>".$s['name']." ". $s['type']." ". $s['level']." ";
}