2017-04-08 70 views
-1

我的网站上有一个搜索栏,它调用了一个在数据库中进行查询的脚本。自动将数组发送到另一个页面

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

我不想去通过会话,因为用户可以有多个选项卡中打开,而我不希望用一个序列化来传递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> 
+0

令人困惑的解释是否可以向我们提供一些代码示例? –

+1

只需在php文件的底部添加表单?并检查您是否收到了发布数据,然后查询进行,然后显示名字,姓氏和年龄。如果您尚未收到发布数据,则只需显示表单。 –

+1

如何处理发布数据并在需要时显示html输出的示例:https://pastebin.com/uPGXEfMz –

回答

-1

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

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

+0

但我不希望任何人留在此页面上,它只是一个查询脚本;) – Buck

相关问题