Deee9994
Deee9994

Reputation: 3

calling values from database to dropdown list, doesn't show all the values

i have a table in my database called categorys, it has two columns cat_id and cat_name ,, i finally managed to get the select right but it doesn't show all of the table rows, there's 22 row it only shows 11 of them ! how can i fix that ? here's the code i used

    $sql = "SELECT cat_id, cat_name FROM categorys";
    $result = $conn->query($sql);

    ?>  

    <select name="taskOption">
    <?php if ($result->num_rows > 0) {
 while($row = $result->fetch_assoc()) { ?>
  <option value="<?php echo $row['cat_id']; ?>>
<?php echo $row['cat_name']; ?>
 </option> <?php } ?>
</select> 
<?php } ?>

Upvotes: 0

Views: 33

Answers (2)

MatthewS
MatthewS

Reputation: 61

You are missing the closing quote after your option value. So it takes two times through before it closes the value. Therefore, only half your rows are showing.

<?php
$sql = "SELECT cat_id, cat_name FROM categorys";
$result = $conn->query($sql);
?>  

<select name="taskOption">
<?php if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()){ ?>
<option value="<?php echo $row['cat_id']; ?>">
<?php echo $row['cat_name']; ?>
</option> <?php } ?>
</select> 
<?php } ?>

Upvotes: 0

Niklesh Raut
Niklesh Raut

Reputation: 34914

Change here, missing closing double quote "

<option value="<?php echo $row['cat_id']; ?>">

Upvotes: 1

Related Questions