0

我想从数据库中填充一个下拉框,然后更新页面以显示结果?我想从下拉列表中的数据库中的 article.title 表中获取所有字段。我希望页面在用户单击提交按钮时更新,我将为它创建。我这甚至可能吗?

<?php

ini_set('display_errors',1); 
error_reporting(E_ALL);

//print_r(PDO::getAvailableDrivers()); 

$config['db'] = array( //This is the config array with the database details
    'host'              => 'localhost',
    'username'          => 'root',
    'password'          => '',
    'dbname'            => 'website'
); 


//echo '<table, th, td {border: 2px solid black; border-collapse="collapse";} >';
echo '<table id="customers"}>';
echo '<link rel="stylesheet" type="text/css" href="style.css">';

echo '<th> one </th>';
echo '<th> two </th>';
echo '<th> three </th>';
echo '<th> four </th>';


$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']        ['dbname'], $config['db']['username'], $config['db']['password']); //Instanciate an PDO Object


$query = $db->query("SELECT `articles`.`title`, `articles`.`hello`, `articles`.`id`, `articles`.`name` FROM `articles` WHERE `articles`.`title` > 1 LIMIT 10");//running a query from the database



$alt=0;
while ($row = $query->fetch(PDO::FETCH_ASSOC)){
 if($alt==0){
  echo '<tr>';
  $alt=1;
 }else{
  echo '<tr class="alt">';
  $alt=0;
 }
 echo '<td>';
 echo $row["title"];
 echo '</td>';
 echo '<td>';
 echo $row["hello"];
 echo '</td>';
 echo '<td>';
 echo $row["id"];
 echo '</td>';
 echo '<td>';
 echo $row["name"];
 echo '</td>';
 echo '</tr>';
}

//print_r($query); //printing a query 



echo '</table>';

echo '<p> Returned ', $query->rowCount(), ' results due to limit set</p>';


//$query = $db->query("SELECT `title` FROM `articles`");//running a query from the database


//$query = $db->query("SELECT * FROM articles");


//print_r($query); //printing a query

//$stmt = $db->prepare($sql);
//$stmt->execute();
//$results = $stmt->fetchAll();

/* $query = $db->query("SELECT `id` FROM `articles`");//running a query from the database

while ($row = $query->fetch(PDO::FETCH_ASSOC)){
echo $row['title'], '<br>';
echo $row['id'], '<br>';
}

}

*/
4

0 回答 0