2013-03-09 32 views
-1

我可以正確填充dropbox,但我無法找到一種方法在單擊提交時在表格中顯示所選項目的數據。下面是代碼:在PHP中使用MySQL填充dropbox,然後單擊提交按鈕後在表格中顯示數據

的index.php

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Αναζήτηση Οφειλών Ανά Πολυκατοικία</title> 
    <link rel="stylesheet" href="tbl_style.css" type ="text/css"/> 
</head> 
<body> 
    <form id="form1" name="form1" method="POST" action="search.php"> 
    <?php 
    include('config.php'); 
    $query = "SELECT DISTINCT odos FROM ofeiles_results ORDER BY odos ASC"; 
    mysql_query("SET CHARACTER SET 'utf8'"); 
    mysql_query("SET NAMES 'utf8'"); 
    $result = mysql_query($query); 
    echo "<select name='polykatoikia'>"; 
    while ($row = mysql_fetch_array($result)) { 
     echo "<option value='" . $row['odos'] . "'>" . $row['odos'] . "</option>"; 
    } 
    echo "</select>"; 
    ?> 
    <input type="submit" name="Submit" value="Select" /> 
    </form> 
</html> 
</body> 

到目前爲止好,保管箱被填充。然後在文件中的search.php我有以下代碼:

的search.php

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Αποτελεσματα Αναζητησης Πολυκατοικιων</title> 
    <link rel="stylesheet" href="tbl_style.css" type ="text/css"/> 
</head> 
</html> 
<?php 
    include('config_barcode.php'); 
    if(isset($_POST['select'])){ 
    $odoss = $_POST['select']; 
    mysql_query("SET CHARACTER SET 'utf8'"); 
    mysql_query("SET NAMES 'utf8'"); 
    $display_query = "SELECT odos FROM ofeiles_results WHERE odos LIKE '" . $odoss . "'"; 
    $result_exoda = mysql_query($display_query) or die(mysql_error()); 
    print $result_exoda; 
    $odos = $row['odos']; 
    $app = $row['perigrafh']; 
    $enoikos = $row['enoikos']; 
    $mhnas = $row['mhnas']; 
    $synolo = $row['synolo']; 
    echo "</br>"; 
    echo "</br>"; 
    echo "</br>"; 
    echo "<table cellpadding='3' cellspacing='0'>"; 
    echo "<tr>"; 
    echo "<th align='center' bgcolor='#FFCC00'><strong>Οδος</strong></th>"; 
    echo "<th align='center' bgcolor='#FFCC00'><strong>Διαμερισμα</strong></th>"; 
    echo "<th align='center' bgcolor='#FFCC00'><strong>Όνομα</strong></th>"; 
    echo "<th align='center' bgcolor='#FFCC00'><strong>Σύνολο</strong></th>"; 
    echo "<th align='center' bgcolor='#FFCC00'><strong>Μήνας</strong></th>"; 
    echo "</tr>"; 
    echo "<td align='center'>".$odos."</td>"; 
    echo " <td align='center'>".$app."</td>"; 
    echo " <td align='center'>".$enoikos."</td>"; 
    echo " <td align='center'>".$mhnas."</td>"; 
    echo " <td align='center'>".$synolo."</td>"; 
    echo "</table></td>"; 
    echo $result_exoda; 
    } 
?> 

我得到的是一個空白頁。我究竟做錯了什麼?謝謝。

+0

空白頁會提示您有錯誤檢查或顯示關閉 – 2013-03-09 09:08:20

+0

請勿使用'mysql_'函數使用PDO。 – ShuklaSannidhya 2013-03-09 09:21:16

回答

0

我用它顯示在表中的數據,你不需要使用許多「回聲」使用循環 您可以在

$sql = "SELECT your_row , another_row , your_row_again FROM your_table_name"; 

,如果你在你的數據庫有更多的行添加更多的行。

$conn = mysql_connect($dbhost, $dbuser); 
if(! $conn) 
    { 
     die('Could not connect: ' . mysql_error()); 
    } 
$sql = "SELECT your_row , another_row , your_row_again FROM your_table_name"; 
mysql_select_db('your_db'); 
$retval = mysql_query($sql, $conn); 
if(! $retval) 
    { 
     die('Could not get data: ' . mysql_error()); 
    } 
echo "<div align = 'center'><table border = '1'>"; 
echo "<th>Your_row_Header</th><th>Row_Header_again</th><th>Row_Header_again</th>"; 
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) 
{ 
    echo "<tr><td align = center>{$row['Your_row1']}</td>". 
     "<td align = center>{$row['Your_Row2']}</td></tr>". 
         "<td align = center>{$row['Your_Row3']}</td>"; 
} 
echo "</table></div><br />"; 
mysql_close($conn); 
相關問題