PHP MYSQL无法在While或For循环中获取数据

时间:2021-01-09 21:37:54

I have made input select tab using mysql database.

我使用mysql数据库制作了输入选择标签。

Using While:

<select name="membership_ID" id="membership" tabindex="1" required="required">
    <option value="">-- Membership Type --</option>
    <?php $get_membership = mysql_query("SELECT * FROM membership");
    while($row_membership = mysql_fetch_array($get_membership, MYSQL_ASSOC)): ?>
        <option value="<?php echo $row_membership['ID']; ?>"> <?php echo $row_membership['name']; ?> </option>
    <?php endwhile; ?>
</select>

using For loop:

使用For循环:

<?php $get_membership = mysql_query("SELECT * FROM membership");
    $numRows = mysql_num_rows($get_membership);
    for($i=1;  $i<= $numRows; $i++){
        $row_membership = mysql_fetch_array($get_membership, MYSQL_ASSOC) ?>
        <option value="<?php echo $row_membership['membership_ID']; ?>"> <?php echo $row_membership['membership_name']." - ".$row_membership['membership_price']." Rs"; ?> </option>
<?php } ?>

this works fine and gives values placed as options when no while loop is there. But when while/for loop places, options in while/for loop are not displayed. Note: table membership contains data.

这种方法很好,当没有while循环时,将值作为选项放置。但是当while / for循环放置时,while / for循环中的选项不会显示。注意:表成员资格包含数据。

1 个解决方案

#1


0  

Try this :

试试这个 :

$row_membership = mysql_fetch_array($get_membership) ?>

#1


0  

Try this :

试试这个 :

$row_membership = mysql_fetch_array($get_membership) ?>