0

This is my code but I don't seem to get anything in the dropdown list. Is there something else I'm supposed to do besides this? Or is there something wrong with my code?

<div class="span10 offset1">
                <div class="row">
                        <h3> Add catagory</h3>
                    </div>
                      <select class="selectpicker" data-style="btn-success" >';

                        <?php
                   include('database.php');

        $query = "SELECT cat_name  FROM  catagory";
$result = mysql_query ($query);
echo "<select name='dropdown' value=''><option>Dropdown</option>";
while($r = mysql_fetch_array($result)) {
 echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}
echo "</select>";
?>

</div>   

2 Answers 2

2

You're referencing $row but assigning the result to $r. Just change the variable:

while($r = mysql_fetch_array($result)) {
    echo "<option value=' " . $r['cat_name'] . " '>" . $r['cat_name'] . " </option>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Eh, guess I'll just have to speed up my typing skills, then!
1

Your variables names look wrong

while($r = mysql_fetch_array($result)) {
 echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}

You loop through the results using $r but use $row[] within the loop. It should probably read

while($row = mysql_fetch_array($result)) {
 echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}

1 Comment

Make sure that you're connected to the MySQL server, and that you've selected the correct database to run your queries against by using mysql_select_db($database_name)

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.