首页 > 解决方案 > Show data after selecting a value from a listbox

问题描述

I want to do this but using php and mysqli. It takes a value and show it below:

http://biblia.cartelesparafacebook.com/bibliajs/#/biblia/genesis/1

Right now Im testing this code, but I need help for achieve this. Please I going to appreciate your help.

<!DOCTYPE html>
<html>
<head>
    
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="/js/scripts.js"></script>
<script>

    $(document).on("change", "#name", function(){

        var elem = $(this),
            id = elem.val();

        $(".info").hide(200); /* HIDE ALL OTHER INFORMATION */

        $(".info-"+id).show(200); /* SHOW THE INFO OF THE SELECTED FULL NAME */

    });

</script>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style>
table, th, td {
    border: 1px solid black;
}
</style>
</head>
<body>
    
    
<?php
require 'connect_bible.php';
$sql = mysqli_query($conn, "SELECT * FROM bible_books");
?>
    <select name="dynamic_data" id="name">
    <?php
        $i=0;
        while($row = mysqli_fetch_array($sql)) 
        {
    ?>
        <option value="<?=$row["idbook"];?>"><?=$row["name"];?></option>
        <?php $i++; 
        } ?>
    </select>
        <?php mysqli_close($conn); ?>
        
        
<?php

$info = '';
require 'connect_bible.php';

$stmt = $conn->prepare("SELECT idverse, name, chapter, verse, text 
        FROM bible_verses
        INNER JOIN bible_books ON bible_verses.idBook = bible_books.idBook 
        LIMIT 30");
        
$stmt->execute();
$stmt->bind_result($idverse, $name, $chapter, $verse, $text);
while($stmt->fetch()){

    echo '<option value="'.$idverse.'">'.$name.'</option>';
    $info .= '<div class="info info-'.$idverse.'" style="display:none">
                  Chapter: '.$chapter.'<br>
                  Verse: '.$verse.'<br>
                  Text: '.$text.'
              </div>';

}
$stmt->close();

echo '</select>';

echo $info;
?>


</body>
</html>

I just tasting this code right now, but I need help for achieve this. Please I going to appreciate your help.

标签: phphtmlmysql

解决方案


推荐阅读