私はpostgreSQL DBから行を表示しようとしています。その前に私は日付でフィルタを使用してどの行を指定する必要があります。そして日付はhtmlの形式で入力する必要があります。PHPとPostgreSQLの2つの日付の間のデータをフォームから選択しますか?
form.php:
<div id = "login">
<form action = "table.php" method = "POST">
From date: <input type = "text" name = "from_date" required>
<input type = "text" name = "referer" style = "display: none" value = "<?=$from_date?>">
<br />
<br />
To date: <input type = "text" name = "to_date" required>
<input type = "text" name = "referer" style = "display: none" value = "<?=$to_date?>">
<input type = "submit" name = "submit" value = "Enter">
</form>
<p>xxxx-xx-x</p>
</div>
table.php:
<!DOCTYPE html>
<html>
<head>
<title>Тестова таблица</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white">
<?
$link = pg_Connect("dbname=Test user=postgres password=1111");
$result = pg_exec("SELECT * FROM import.mock_data WHERE date BETWEEN '" . $from_date . "' AND '" . $to_date . "'ORDER by id DESC");
?>
<?
if (!$link)
{
die('Error: Could not connect: ' . pg_last_error());
}
$query = pg_exec($link, "select * from import.mock_data;");
$result = pg_query($query);
$i = 0;
echo '<html><body><table><tr>';
while ($i < pg_num_fields($result))
{
$fieldName = pg_field_name($result, $i);
echo '<td>' . $fieldName . '</td>';
$i = $i + 1;
}
echo '</tr>';
$i = 0;
while ($row = pg_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '</tr>';
$i = $i + 1;
}
pg_free_result($result);
echo '</table></body></html>';
?>
</body>
</html>
とエラー:
Notice: Undefined variable: from_date in C:\WEB\Apache24\htdocs\table.php on line 15
Notice: Undefined variable: to_date in C:\WEB\Apache24\htdocs\table.php on line 15
Warning: pg_exec(): Query failed: ERROR: invalid input syntax for type date: "" LINE 1: SELECT * FROM import.mock_data WHERE date BETWEEN '' AND ''...^in C:\WEB\Apache24\htdocs\table.php on line 15
Warning: pg_query() expects parameter 1 to be string, resource given in C:\WEB\Apache24\htdocs\table.php on line 26
Warning: pg_num_fields() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 30
Warning: pg_fetch_row() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 39
Warning: pg_free_result() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 54
は、あなたが私を助けることができる、私はこれを達成し、この時点で お願いします?
編集: 他のエラーをクリアするために検索しました。誰かが私を助けることができる場合は、[編集] 2
Warning: pg_query() expects parameter 1 to be string, resource given in C:\WEB\Apache24\htdocs\table.php on line 25
Warning: pg_num_fields() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 29
Warning: pg_fetch_row() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 38
Warning: pg_free_result() expects parameter 1 to be resource, null given in C:\WEB\Apache24\htdocs\table.php on line 53
:)をしてください。
を申し訳ありませんああ、私は機能のためのより具体的な検索を忘れていました。このコードでは、今その作品:
<?
$link = pg_Connect("dbname=Test user=postgres password=1111");
if (!$link)
{
die('Error: Could not connect: ' . pg_last_error());
}
$result = pg_query($link, "SELECT * FROM import.mock_data WHERE date BETWEEN '" . $_POST['from_date'] . "' AND '" . $_POST['to_date']. "'ORDER by id DESC");
$i = 0;
echo '<html><body><table><tr>';
while ($i < pg_num_fields($result))
{
$fieldName = pg_field_name($result, $i);
echo '<td>' . $fieldName . '</td>';
$i = $i + 1;
}
echo '</tr>';
$i = 0;
while ($row = pg_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '</tr>';
$i = $i + 1;
}
pg_free_result($result);
echo '</table></body></html>';
?>
以下のように変更これは、([PHPで基本的なフォームの処理を行う方法]の場合であるhttps://www.w3schools.com /php/php_forms.asp)。 – icecub
はい、そうです。私はこれを見ましたが、前のフォームで間違いを犯しました。 – Hristian