Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
149 views
in Technique[技术] by (71.8m points)

php - Can t get a text as value in select tag

I have a select drop down where I want in the value the text from db. If I have a value like "word1 word2" I get in post only first word. How can I do to have all text?

<div class="form-group">
 <label>Functie</label>
 <select name="functie" id="functie" class="form-control">
 <option value="">&nbsp;</option>
<?php 
$stmt = $connection->query("SELECT * from functii order by functie ASC");
while ($row = $stmt->fetch_assoc()) {
echo "<option value=$row[functie]>$row[functie]</option>";
}
echo "</select>";
?>
 </select>
</div>

So basically $row[functie] can have as value 1,2 or three words....and in my case I get only first one if i select one of these

Thank you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to change how you are building your option lines in the loop. The value needs to be enclosed in quotes. Change:

while ($row = $stmt->fetch_assoc()) {
    echo "<option value=$row[functie]>$row[functie]</option>";
}

to

while ($row = $stmt->fetch_assoc()) {
    echo '<option value="' . $row[functie] . '">' . $row[functie] . '</option>';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...