Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PHP和PostgreSQL中的表单选择两个日期之间的数据?_Php_Html_Postgresql - Fatal编程技术网

通过PHP和PostgreSQL中的表单选择两个日期之间的数据?

通过PHP和PostgreSQL中的表单选择两个日期之间的数据?,php,html,postgresql,Php,Html,Postgresql,我试图显示postgreSQL数据库中的一行。在此之前,我需要指定按日期筛选的行。日期需要以html的形式输入。 在这段时间里,我做到了这一点: form.php: <div id = "login"> <form action = "table.php" method = "POST"> From date: <input type = "text" name = "from_date" required> &

我试图显示postgreSQL数据库中的一行。在此之前,我需要指定按日期筛选的行。日期需要以html的形式输入。 在这段时间里,我做到了这一点:

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>
你能帮帮我吗

编辑: 好的,谢谢,现在我搜索以清除其他错误。如果有人能帮助我,请:

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
编辑2:

哦,对不起,我忘了搜索更具体的函数。现在,此代码可以正常工作:

    <? 
$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>';
?>
就像下面那样改变

$result = pg_exec("SELECT * FROM import.mock_data WHERE date BETWEEN '" . $_POST['from_date'] . "' AND  '" . $_POST['to_date']. "'ORDER by id DESC");

这将是一个例子。是的,没错。我看到了这个,但我以前在表格中犯了一个错误。你听说过吗?因为你就是这样邀请他的!
    <? 
$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>';
?>
$result = pg_exec("SELECT * FROM import.mock_data WHERE date BETWEEN '" . $_POST['from_date'] . "' AND  '" . $_POST['to_date']. "'ORDER by id DESC");