0

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 } ?>
3
  • can you show me the value here from DB from which it is not displayed Commented Apr 23, 2016 at 5:51
  • ya give me a sec .. i'll screenshot the table and the output Commented Apr 23, 2016 at 5:51
  • @Deee9994 if you do print_r($row), what output do you get? Can you post it in your question too please? Commented Apr 23, 2016 at 5:54

2 Answers 2

1

Change here, missing closing double quote "

<option value="<?php echo $row['cat_id']; ?>">
Sign up to request clarification or add additional context in comments.

1 Comment

happy to help you.
0

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 } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.