[英]Displaying data with php depending on what is selected in select option
Is it possible to display data of the current selected option, from mysql
using php
only?. 是否可以仅使用
php
从mysql
显示当前选定选项的数据? So my select option
works fine and it displays good results. 因此,我的
select option
可以正常工作,并且显示出良好的效果。 But I want 2 other form-group
divs
to display data depending on what is currently selected in select option
. 但是我希望另外2个
form-group
divs
显示数据,具体取决于select option
当前选择的内容。 Is that possible using php
only or is javascript
necessary? 是否有可能仅使用
php
或javascript
是必需的?
Html HTML
<div class="form-group">
<label for="naslov">Naslov</label>
<input type="text" class="form-control" id="naslov" name="naslov" value="<?php echo $titedit; ?>">
</div>
<div class="form-group">
<label for="oglas">Sadržaj</label>
<textarea class="form-control" id="oglas" name="oglas" rows="5" ><?php echo $contedit; ?></textarea>
</div>
PHP 的PHP
<?php
session_start();
include_once("db.php");
$sql = "SELECT * FROM news";
$query = mysqli_query($conn, $sql);
$title = $row['title'];
$mxnr = mysqli_num_rows('$query');
if ($mxnr > 0) {
echo '<select class="form-control">';
$counter = 1;
while($row = mysqli_fetch_array($query)) {
if($counter == 1){
echo '<option ' . ($counter == 1 ? 'selected' : '') . ' value="opt' . $counter . '">' . $row["id"] . '. ' . $row["title"] . '</option>';
$titedit = $row['title'];
$contedit = $row['content'];
}else{
echo '<option value="opt' . $counter . '">' . $row["id"] . '. ' . $row["title"] . '</option>';
}
$counter++;
}
echo '</select>';
} else {
echo "0 results";
}
?>
You will need javascript for that, since PHP loads before everything else, you can use JQuery to change the divs when you select something making it interactive and responsive. 您将需要使用javascript,因为PHP会先加载所有其他内容,所以当您选择使其具有交互性和响应性的内容时,可以使用JQuery更改div。
If i may add my opinion, rely on javascript, its really usefull most of the time and will help you a lot. 如果我可以发表自己的看法,请依靠javascript,它在大多数情况下都非常有用,将为您提供很多帮助。 Consider JQuery.
考虑一下JQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.