Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:33:37+00:00 2026-06-05T04:33:37+00:00

I am using a dynamically generated query string to display results from a search

  • 0

I am using a dynamically generated query string to display results from a search form for some reports – there are 5 search fields and $query2 could contain nothing or 5 additional search values.

$query="SELECT * from employee_work where company_id='$company_id' $query2";

When I POST the form I get the data displayed on screen which is great. I also then am using TCPDF to offer a PDF download of the data. I currently also the class for TCPDF via POST:

if($_POST['PDF']) {
    do the TCPDF stuff......
}

<div id="export-buttons">
<form name="export" method="post" action="">
<input type="submit" name="PDF" value="PDF" class="button pdf">
</div>

The problem is that when a user clicks on the PDF button the POST array now only contains the value for the submit button and NOT the $query2 data from earlier so when I use TCPDF it outputs all the data and ignores the $query2 part of the search string.

How can I address this so either the original $query2 data stays available OR have anther way of checking if the form button has been clicked without overwriting the contents of POST? Can I use javascript to do this?

Thanks
Jason

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:33:39+00:00Added an answer on June 5, 2026 at 4:33 am

    why dont you add hidden inputs that have the values of the criteria from the search? That way when the user posts the request for the PDF you get also those fiels and can use them (AFTER making sure the values are SAFE) in the query.

    Other safer way is to store in the session an object or array with the parameters that made the list and then pass the identifier of that search as a hidden input to the PDF form, like:

    $_SESSION['sc0000001'] = array('field1'=>'value1', 'field2'=>'value2', 'field3'=123);
    ...
    <form>
    <input type="hidden" name="sc" value="0000001" />
    ...
    </form>
    

    when you post the form you get the identifier of the search and create the query with the criteria assign to session…

    EDITED:
    html before posting list criteria:

    <form>
    <input type="text" name="filter1" value="" />
    <input type="text" name="filter2" value="" />
    <input type="text" name="filter3" value="" />
    <input type="text" name="filter4" value="" />
    <input type="text" name="filter5" value="" />
    ...
    <input type="submit" value="go go go" />
    </form>
    

    PHP that gets the filters, builds query, gets results and stores in session.

    $sql = " select * from table_name where 1 ";
    
    $arrFilters = array();
    for($i=1;isset($_POST['filter'.$i]) && trim($_POST['filter'.$i])!="";$i++) { 
    $arrFilters['filter'.$i] = mysql_real_escape_string($_POST['filter'.$i]);
    $sql.=" AND filter".$i."=".$arrFilters['filter'.$i];
    }
    // here you should have the complete $sql with the filters supplied
    
    // lets save this search, we are going to keep only the last search from this user in his session.
    $_SESSION['listingFilters'] = $arrFilters;
    

    HTML with search results and after the form to get pdf:

    <form>
    
    <input type="submit" value="get pdf" />
    </form>
    

    PHP:
    After the post to get the pdf we go check if there are filters

    $sql = " select * from table_name where 1 "; // basic query
    // get the filters array from session
    $arrFilters = isset($_SESSION['listingFilters']) ? $_SESSION['listingFilters'] : array();
    foreach($arrFilters as $filter => $value) { // for each filter add it to the query
    $sql.=" AND filter".$i."=".$arrFilters['filter'.$i];
    }
    // here you should have the complete $sql with the filters in session
    // and can do your pdf magic
    

    Add pepper and salt to your pleasure (you need to revise the code to work for you and maybe also the query if you are using text has filters)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate a query dynamically using textbox values from my Bookings form
I currently am using a dynamically generated list view in jQuery mobile to display
I have a dynamically generated form that I would like to submit using Ajax.
I have a drop down list which is dynamically generated using ajax on page
I'm creating a dynamically generated PDF using FPDF. My PDF requires many exactly horizontal/vertical
In my application I am using a canvas which is dynamically generated at runtime.
i created some text boxes dynamically using javascript, now i want to access them
I am trying to dynamically generate linqtosql query using LinqKit . I would like
I'm trying to get the MAX on a column which is generated dynamically using
Is it possible to have checkboxes with a gridview that is dynamically generated from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.