【问题标题】:Post array automatically to one page at another将数组自动发布到另一页
【发布时间】:2017-09-04 03:12:24
【问题描述】:

我的网站上有一个搜索栏,它调用在数据库中进行查询的脚本。

查询完成后,我想将结果返回到第一页,但是:

我不想通过会话,因为用户可以打开多个选项卡,并且我不想通过序列化在 url 中传递结果,因为结果在搜索栏中确实不漂亮。

您知道如何在不使用 ajax 的情况下将数组从一个页面传递到另一个页面吗?

我发送一个值:search.php

<form action="../core/data_search.php" method="post" id="research_form">
  <input type="text" id="search" name="search" />
  <input type="submit" value="Rechercher" id="research" />
</form>

我的研究脚本是:

<?php
session_start();
require_once("conf.php");

$id = $_SESSION["id"];
if ($_POST && !empty($_POST)) {
    $data = $_POST['search'];
    //Recherche d'une adresse mail
    if ( preg_match ( " /^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/ " , $data) ){
        $column = "WHERE `email` = '$data' AND `add_by_user` = '$id'";
    //Recherche d'un code postal complet (ou la recherche strictement égal à la colonne)    
    }elseif (preg_match(" /^(?:(?:(?:0[1-9]|[1-8]\d|9[0-5])(?:\d{3})?)|97[1-8]|98[4-9]|2[abAB])$/ ", $data)) {
        $column = "WHERE `zip_code` LIKE '$data%' AND `add_by_user` = '$id'";
    }elseif (preg_match(" /^([a-zA-Z]+[ '-]?[a-zA-Z]+){1,30}$/ ", $data)) {
        $column = "WHERE `first_name` = '$data' OR `last_name` = '$data' AND `add_by_user` = '$id'";
    //Recherche par date de fin de formation
    }elseif (preg_match(" /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/ ", $data)) {
        $column = "WHERE `end_formation_date` = '$data' AND `add_by_user` = '$id' ";
    }else{
        header("Location : ../search.php?return=error");
        exit();
    }

    $data = $bdd->query("SELECT * FROM customers $column ");
    $result = $data->fetchAll(PDO::FETCH_ASSOC);

    // Here i replace the end of script for use Ajax
    if($result){
        echo json_encode($result);
    }
}

我需要在 search.php 中有这种类型的结果

<form action="../core/data_search.php" method="post" id="research_form">
    <input type="text" id="search" name="search" />
    <input type="submit" value="Rechercher" id="research" />
</form>
<section>
    <p>firstname : <?=$firstname?> <!--received to my queries script--></p>
    <p>lastname  : <?=$lastname?> <!--received to my queries script--></p>
    <p>age       : <?=$age?> <!--received to my queries script--></p>
</section>

【问题讨论】:

  • 解释混乱,能否提供一些代码示例?
  • 只在php文件底部添加表单?并检查您是否已收到发布数据并继续查询,然后显示名字、姓氏和年龄。如果您还没有收到帖子数据,则只需显示表单即可。
  • 我如何处理发布数据并在需要时显示 html 输出的示例:pastebin.com/uPGXEfMz
  • 谢谢安德鲁 :)

标签: php arrays send


【解决方案1】:

当查询完成时,结果已经存储在变量中。所以你可以在页面上显示。

如果要将其转移到另一个页面,可以将序列化的数组存储到 HTML 隐藏表单元素中。 这需要用户提交表单以将数组传递到下一页。

【讨论】:

  • 但是我不想让任何人留在这个页面上,它只是一个查询脚本;)
猜你喜欢
  • 2023-03-13
  • 1970-01-01
  • 2015-12-28
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 2016-04-05
  • 1970-01-01
相关资源
最近更新 更多