如何在echo中显示类别值

时间:2016-02-07 08:55:02

标签: php html mysql

$db_user="root";<br>
$db_pswd="";<br>
$db_host="localhost";<br>
$db_dbname="szabist";<br>

$db_con=mysqli_connect($db_host,$db_user,$db_pswd,$db_dbname);<br>
    if($db_con->connect_error){<br>
        die("connecting error" . $db_con->connect_error()); <br>
    }<br>

 $cat_query = $db_con->query('SELECT classname FROM category');<br>
$cat_row = mysqli_fetch_array($cat_query);<br>
echo '
    <table class="table-condensed">
        <tr>
            <td><label>Book Title:</label></td>
            <td><input type="text" name="book_title"></td>
        </tr>
        <tr>
            <td><label>Category:</label></td>
            <td><select name="category_id">
            <option value="'.$cat_row['classname'].'">'.$cat_row["classname"].'</option>
            </select></td>
        </tr>';

1 个答案:

答案 0 :(得分:0)

$db_user="root";   
$db_pswd="";   
$db_host="localhost";    
$db_dbname="szabist";

$db_con=mysqli_connect($db_host,$db_user,$db_pswd,$db_dbname);
    if($db_con->connect_error){
        die("connecting error" . $db_con->connect_error); 
    }

function add_new_book(){

global $db_con;    

 $cat_query = $db_con->query('SELECT classname FROM category');
$cat_row = mysqli_fetch_array($cat_query);
echo '
    <table class="table-condensed">
        <tr>
            <td><label>Book Title:</label></td>
            <td><input type="text" name="book_title"></td>
        </tr>
        <tr>
            <td><label>Category:</label></td>
            <td><select name="category_id">
            <option value="'.$cat_row['classname'].'">'.$cat_row["classname"].'</option>
            </select></td>
        </tr>';    }