[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Opening a table in a new page

I have managed to write a script that will run a count query and display the results. I would now like to add some code to be able to display the details of the query if the user chooses to do so. For this, I would need the script to pass two variables to the new page and run the query and display the results. I started by simply trying to pass a variable taken from the main page to the new page and display the content, but I didn't get the desired results. Here is the code that I have so far:

---adserv.php
//If the user presses the "View Results" button, view_results.php is supposed be opened.
elseif (strcmp("Submit", $command) == 0)
{
 include "view_results.php";
}

--view_results.php
<?php
  //These two variables are in adserv.php
  echo $NewAds;
  echo $LateAds;
?>

I was able to use this kind of analogy with another page, but this one instead of displaying the results, only ran an update query. Any ideas will be appreciated. Thanks!

0
horalia
Asked:
horalia
  • 15
  • 10
1 Solution
 
soapergemCommented:
It is techincally supposed to behaving in exactly the same way you'd like it to, so the problem is likely stemming from something else. First of all, are you positive that it successfully enters this elseif clause? Secondly, you could do something like this:

---adserv.php
//If the user presses the "View Results" button, view_results.php is supposed be opened.
elseif (strcmp("Submit", $command) == 0)
{
 include "view_results.php";
  echo $NewAds;
  echo $LateAds;
}

--view_results.php
<?php
  //Moved echo commands
?>

That's not a permanent fix right there--just a method to try and debug. Can you provide a little more info about these variables, too? Does view_results.php run queries and compile these variables, or does adserv.php handle this?
0
 
horaliaAuthor Commented:
I'm positive that the elseif is working. I placed an echo statement in the view_results.php page, and the string was displayed when I pressed the submit button. $NewAds and $LateAds are variables that hold the results for two queries that are run in adserv.php. My main goal is to run a query and display the results in a new page to make this project a little more organized and not display everything in only one page.
0
 
horaliaAuthor Commented:
OK, I realized my mistake, but I'm still having a problem passing the variables. Instead of doing an elseif, I just open the page using javascript. Here's the code:

--adserv.php
//When user presses button, runs doView.
<input type="button" class="add" value="View Results" onclick="doView(this)">

--tools.js
function doView(button)
{
  button.form.command.value = "view";
  button.form.action = "view_results.php";
  button.form.submit();
}

--view_results.php
<?php
  echo "mine";
?>

If instead of the line: echo "mine"; I add variables that are contained in adserv, nothing is displayed. I just need to pass one variable and then run the query using this variable. I'm sure it is something quite simple and it has already been posted somewhere out there, but I'm very new to web programming and I'm still trying to get a grasp of it. I'll increase the points, I would like to have this code running by the end of today. Thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
soapergemCommented:
Is there a particular reason you're using type="button" rather than type="submit"? You could remove the submit() command from your doView() function, and then define your form like this:

<form [...] onsubmit="doView(this)">

You would have to adjust it, since the "this" you would entering is no longer a form element, but the form itself. Worth a shot.
0
 
horaliaAuthor Commented:
Not really, I'm just basing my code on an example I saw on a book. To make matters worse, I haven't worked with javascript either...
0
 
soapergemCommented:
I'd probably recommend that, just as a syntactical thing. If a button consistently submits the form, it should be a "submit" type, not a "button" type. But as for the variables that are compiled not showing up, I need to clarify something. Are you sure that the right document is doing the include? Or that you're redirecting to the correct document? Here's what I mean. Let's say your two PHP files are compiled like this:

---adserv.php
$variables = [something];    // compile all the variables
include 'view_results.php';

--view_results.php
echo $variables;

Case 1 (good):    JavaScript redirects to adserv.php
Case 2 (bad):     JavaScript redirects to view_results.php

Alternatively, here's another way to think about it. Let's say, now, that your PHP files are instead like this:
---adserv.php
$variables = [something];    // compile all the variables

--view_results.php
include 'adserv.php';
echo $variables;

Case 1 (good):    JavaScript redirects to view_results.php
Case 2 (bad):     JavaScript redirects to adserv.php

-------------------------------------------------------------------------------

What I'm pointing out here is that just because one file includes another doesn't mean the converse is true. (In fact, it's not true.) You can't call the file that doesn't have the include statement in it and expect the other file to do its magic. I just wanted to confirm that the right pages are making the right includes.
0
 
horaliaAuthor Commented:
I'm posting all my code, I'm starting to get a bit confused now. I have all the code in one page only. view_results.php is only:
<?php
echo $NewAds
?>

--adserv.php
<html>
<head>
      <link rel="stylesheet" href="myStyle.css" type="text/css">
      <SCRIPT LANGUAGE="javascript" TYPE="text/javascript" SRC="tools.js"></SCRIPT>
      <SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>
      <SCRIPT LANGUAGE="JavaScript">
            var cal = new CalendarPopup();
      </SCRIPT>
</head>
<body>

<?php
//Connect to the server.
$link = mysql_connect("", "", "");
//Connect to the db.
mysql_select_db("dbads", $link);
?>

<form method="POST" name="data" action="adserv.php">
<input type="hidden" name="command">
<input type="hidden" name="periodname">
<input type="hidden" name="pstartdate">
<input type="hidden" name="penddate">

<!-- Table Title-->
<table class="title" height="20" cellSpacing="0" cellPadding="0" width="750" border="0">
      <tr>
            <th class="title" valign="bottom" class="title">
                  New and Late Ad Report
            </th>
      </tr>
</table>

<br>

<!-- Table Data to Enter -->
<table height="20" cellSpacing="0" cellPadding="0" width="750" border="0">
      <!-- Row Headings -->
      <tr>
            <th class="heading" width="150" align="left">Select a date:</th>
            <th class="heading" width="300" align="left">Select a start/end date:</th>
            <th class="heading" width="150" align="left">Select a period:</th>
            <th class="heading" width="150" align="left">Select a user:</th>
      </tr>
      
      <!-- Row containing items to enter data -->
      <tr>
            <!-- ENTER A DATE -->
            <td class="item" width="150">
                  <input class="textbox" type="text" name="selDate" value="" size="10">
                  <input type="image" align="middle" value="cal1" src="pdate.gif" name="cal1" onclick="cal.select(document.forms['data'].selDate,'cal1','MM/dd/yyyy'); return false;">                  
            </td>
            
            <!-- ENTER START AND END DATE -->
            <td class="item" width="300">
                  <input class="textbox" type="text" name="startDate" value="" size="10">
                  <input type="image" align="middle" value="cal2" src="pdate.gif" name="cal2" onclick="cal.select(document.forms['data'].startDate,'cal2','MM/dd/yyyy');return false;">
                  <input class="textbox" type="text" name="endDate" value="" size="10">
                  <input type="image" align="middle" value="cal3" src="pdate.gif" name="cal3" onclick="cal.select(document.forms['data'].endDate,'cal3','MM/dd/yyyy');return false;">                  
            </td>
            
            <!-- SELECT A PERIOD -->
            <td class="item" width="150">
            <select size="1" class="textbox" id="periodname" name="periodname" onChange="getPeriodDates(this)">
                        <option value="">-</option>
                        <?php
                              //Creates query to retrieve the data to be used in the drop down box.
                              $query="SELECT PeriodName, StartDate, EndDate FROM tblPeriod";
                              if ($hResult=mysql_query($query))
                              {
                                      while ($hFetch=mysql_fetch_array($hResult))
                                      {
                                        $periodname=$hFetch["PeriodName"];
                                        $pstartdate=$hFetch["StartDate"];
                                        $penddate=$hFetch["EndDate"];
                                        echo "<option value='$periodname||$pstartdate||$penddate'\">".$periodname."</option>";
                                      }
                              }
                        ?>
                  </select>
                  
            </td>
            
            <!-- SELECT A USER -->
            <td class="item" width="150">
                  <select size="1" class="textbox" id="username" name="username">
                        <option value="">-</option>
                        /*
                        <?php
                              //Creates query to retrieve the data to be used in the drop down box.
                              $query="SELECT PeriodName, StartDate, EndDate FROM tblPeriod";
                              if ($hResult=mysql_query($query))
                              {
                                      while ($hFetch=mysql_fetch_array($hResult))
                                      {
                                        $periodname=$hFetch["PeriodName"];
                                        $startdate=$hFetch["StartDate"];
                                        $enddate=$hFetch["EndDate"];
                                        echo "<option value='$periodname||$startdate||$enddate'\">".$periodname."</option>";
                                      }
                              }
                        ?>
                        */
                  </select>
            </td>
            
      </tr>
</table>

<input class="add" type="button" value="Submit" onclick="doSave(this, 'Save')"></td>



<?php

//COMMAND
if (isset($_POST["command"]))
  $command = $_POST["command"];
//SELECTED DATE
if (isset($_POST["selDate"]))
      $postselDate = $_POST["selDate"];
//START DATE
if (isset($_POST["startDate"]))
  $poststartdate = $_POST["startDate"];
//END DATE
if (isset($_POST["endDate"]))
  $postenddate = $_POST["endDate"];
//PERIOD NAME
if (isset($_POST["periodname"]))
  $postperiodname = $_POST["periodname"];
//PERIOD START DATE
if (isset($_POST["pstartdate"]))
  $postpstartdate = $_POST["pstartdate"];
//PERIOD END DATE
if (isset($_POST["penddate"]))
  $postpenddate = $_POST["penddate"];
 
//COMPARE COMMAND, IF IT IS SAVE, CHECK INFO AND RUN APPROPRIATE QUERIES. DISPLAY INFO.
if (strcmp("Save", $command) == 0)
{
  //CHECK FOR MISSING PARAMETERS
  //Check that a date has been entered.
  if ($postselDate == null AND $poststartdate == null AND $postenddate == null AND $postperiodname == null)
        die("Enter a date");      
  //Check that only a date or period has been entered.
  if ($postselDate != null AND $postperiodname != null)
        die("Either enter a date or select a period");      
  //Check that only a date or a date range has been selected.      
  if ($postselDate != null AND ($poststartdate != null OR $postenddate != null))
        die("Either enter a single date or a date range");
  //Check that only a period or a date range has been selected.      
  if ($postperiodname != null AND ($poststartdate != null OR $postenddate != null))
    die("Either enter a date range or select a period");
  //Check that if a start date has been entered, an end date has also been entered.
  if ($poststartdate == null AND $postenddate != null)
    die("Enter a start date");
  if ($poststartdate != null AND $postenddate == null)
    die("Enter an end date");
  //Check that end date is higher than start date.
  if ($poststartdate > $postenddate)
    die("End date must be later than start date.");

  //Assign a variable to be used in case statement.
  if ($postselDate != null AND $poststartdate == null AND $postenddate == null AND $postperiodname == null)
  {
    $parameterType = "sglDate";
  }
  elseif ($poststartdate != null AND postenddate != null AND $postselDate == null AND $postperiodname == null)
  {
    $parameterType = "dteRange";
  }
  elseif (postperiodname != null AND $postselDate == null AND $poststartdate == null AND $postenddate == null)
  {
    $parameterType = "dtePeriod";
  }
  else
  {
        die("Error");
  }
 
  //Create queries depending on what parameter has been entered.  
  switch ($parameterType)  
  {
        case "sglDate":
            $queryNew = "SELECT COUNT(job_id) from tblads WHERE DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');";
            $queryLate = "SELECT COUNT(if(TIMEDIFF(deadline, adintime)<0,'late','')) FROM tblads WHERE ((if(TIMEDIFF(deadline, adintime)<0,'late','')='late')) AND DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');";
            $queryResults = "SELECT * from tblads WHERE DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');";
      break;
        case "dteRange":
          $queryNew = "SELECT COUNT(job_id) from tblads WHERE DATE(action_time)>=STR_TO_DATE('$poststartdate','%m/%d/%Y') AND DATE(action_time)<=STR_TO_DATE('$postenddate','%m/%d/%Y');";
          $queryLate = "SELECT COUNT(if(timediff(deadline,adintime)<0,'late','')) FROM tblads WHERE ((if(timediff(deadline,adintime)<0,'late','')='late')) AND DATE(action_time)>=str_to_date('$poststartdate','%m/%d/%Y') AND DATE(action_time)<=str_to_date('$postenddate','%m/%d/%Y');";
        break;
      case "dtePeriod":
          $queryNew = "SELECT COUNT(job_id) FROM tblads WHERE DATE(action_time)>='$postpstartdate' AND DATE(action_time)<='$postpenddate';";
          $queryLate = "SELECT COUNT(if(timediff(deadline,adintime)<0,'late','')) FROM tblads WHERE ((if(timediff(deadline,adintime)<0,'late','')='late')) AND DATE(action_time)>='$postpstartdate' AND DATE(action_time)<='$postpenddate';";            
  } //Closes switch
            
      //Runs both queries
      $resultNew = mysql_query($queryNew, $link);
              if(!$resultNew)
                    die("Invalid query: ".mysql_error()."<br>".$queryNew);      
      $resultLate = mysql_query($queryLate, $link);
                if(!$resultLate)
                    die("Invalid query: ".mysql_error()."<br>".$queryLate);            
        //Fetches the query's result            
      while($row = mysql_fetch_array($resultNew))
        {
          $NewAds = $row[0];
        }
        while($row = mysql_fetch_array($resultLate))
    {
          $LateAds = $row[0];
    }
   
    if ($NewAds == 0)
    {
          echo "There are no ads for this date.";
    }
    else
    {
    //Create table to hold queries results.
      ?>
        <table class="title" height="20" cellSpacing="0" cellPadding="0" width="300" border="0">
      <tr>
            <th class="heading" width="100" align="center">Total New Ads</th>
            <th class="heading" width="100" align="center">Total Late Ads</th>
            <th class="heading" width="100" align="center">Percentage</th>
      </tr>
      <tr>
            <td class="item" width="100" align="center"><?php echo $NewAds ?></td>
            <td class="item" width="100" align="center"><?php echo $LateAds ?></td>
            <td class="item" width="100" align="center"><?php echo number_format($LateAds/$NewAds*100,2,'.','').'%' ?></td>
      </tr>
      </table>
      <?php
      echo '<input type="button" value="Go To" onClick="location.href=\'view_results.php\'">';
    }
}
?>

</table>
</form>
</body>
</html>
0
 
soapergemCommented:
You said that view_results.php only contains this:
<?php
echo $NewAds
?>

That literally would not do anything. You need to define $NewAds somehow in that file. You DID define this in adserv.php when you wrote "$NewAds = $row[0];" Clearly, a value (namely $row[0]) is stored into $NewAds. However, view_results.php has no idea that adserv.php exists because you haven't included it. So what you want to do is something like this:

--view_results.php
<?php
include 'adserv.php';    //  defines the value of $NewAds
echo $NewAds
?>

Unfortunately, adserv.php, as you have it right now, does some output of its own. So if you ran the commands above, it would (1) output absolutely everything that adserv.php outputs, from <html> to </html> and (2) output $NewAds.



What you need to do:

Create a file (maybe you still want to call it adserv.php), that runs queries and does its business to compile variables like $NewAds. However, ensure that this file makes no output at all. All it does is store values into $NewAds, and any other variables you enter into it. Then, when you use the command "include 'adserv.php';" (or whatever filename you choose), these variables will be defined. Thus, you can use them freely in your code. I'm not entirely confident that I'm explaining this clearly, so please ask if you're confused about anything.
0
 
horaliaAuthor Commented:
No, you are. As a matter of fact, I'm reading a wrox PHP book and has an example organized just like you suggested to do so. Let me think about how I'm going to put everything together, and I'll post in about an hour. Just came back from a 1 hr walk to cool off, I was starting to get frustrated!
0
 
horaliaAuthor Commented:
One question, where is mysql_fetch_array run?
0
 
horaliaAuthor Commented:
OK, I'm quite stuck now.... Just to understand the concepts I created a file named mine.php. Here's the code:
--mine.php
<?php
include "myVar.php";
echo $myname;
?>

Here's the code for myVar.php
--myVar.php
<?php
$myname = "Mine";
?>

Now, how would I create a submit button to display the contents of $myname when pressed?

0
 
soapergemCommented:
--mine.php
<?php
include "myVar.php";
if ( isset($_POST['submit']) )
{
    echo $myname;
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="submit" value="1" />
</form>
</body>
</html>

--myVar.php
<?php
$myname = "Mine";
?>


-----------------------------------------------------------------
EXPLANATION:

myVar.php was still the same in the case. It does what it needs to do in order to load some variables. In this particular case, it's pretty short and sweet, immediately loading only one variable called $myname. But in reality, you could have it do database queries and whatnot in order to load more complex data.

I added some HTML to mine.php in order to give you a submit-button. Notice that the form action is $_SERVER['PHP_SELF']. The document would print something like "/root_path/mine.php" right there. It's kind of just my own habit to use PHP_SELF, but it would have been equally valid to just write action="mine.php". Now, I chose to set the method to "post". This was a completely arbitrary choice; it would have been just as good to say method="get".

Post and get variables are whatever <input>s, <select>s, and <textarea>s you have in the form that have a name-attribute assigned to them. Post variables are passed invisibly, and are therefore good when the user is entering a lot of data (like posting a message to a bulletin board, for example). Get variables are automatically appended to the URL: so--had we used them--pressing submit would have brought you to mine.php?submit=1.

It's generally common practice not to give a name-attribute to your submit buttons since buttons really shouldn't hold data, but for this example I wanted to keep it rather short and sweet. Usually there would be enough other data there in the form, so it might look more like this:
<input type="text" name="query" value="" />
<select name="category">
<option value="1">Category 1</option>
<option value="2">Category 2</option>
</select>
<input type="submit" value="Submit" />

And then you could have used a command like this instead:
if ( isset($_POST['query']) )

For get variables, you could use isset($_GET['whatever'])

You could also move the include() statement inside the conditional, if you wanted to. Doesn't make that much of a difference; your preference really. If you wanted it to load data from myVar.php ONLY if some part of the form was submitted, then that would be a good idea.

Also, you can do more strict tests than just checking if the variables have been set to something, and instead check if the variable has a value that actually has any length to it, if it's equal to a specific value, if it's alphanumeric, etc. For example:
if ( isset($_POST['submit']) )
if ( strlen($_POST['submit']) )
if ( $_POST['submit'] == 1 )
if ( preg_match('/[a-z0-9]/i', $_POST['submit']) )

...and so on. Sorry for the long-winded answer, but I hope it helps you.
0
 
soapergemCommented:
On second thought, in mine.php, it would be better to move the <?php ?> section between the <body> tag and
<form> tag, so that the output actually shows up in the <body> of your document. It will show up either way, but that way would be considered the "right way" of doing it.
0
 
horaliaAuthor Commented:
Thanks soapergem. I followed your suggestion, but I believe that I fell into the same little trap again. Here's an explanation of what I did:

1. I erased all of the queries and parameter checking from the file named "ad_report.php". (I had previously named it adserv.php) I only left the following:
a) Connection to the server (to retrieve period name and dates)
b) Form creation (<form name="data" method="POST" action="ad_report_results.php">)
c) Table to input data
d) Command button (<input class="add" type="submit" value="Submit">)

2. I created another file named "ad_report_results.php" where I added the following:
a) Connection to the server
b) Assigned posted data to new variables.
c) Checked for missing parameters.
d) Case assignment (to know which query to run)
e) Queries
f) Ran the query results
g) Fetched the query results
h) Created a table to hold query results. Here's where again I get stuck... I created two buttons to allow the user to view the query results. One where the user will view all results and another one where the user will only view the late ads. How can I do this? Do I create another form, with a POST method and direct it to a new file? I remember reading on this loooong post that you suggested me to use one page to hold the queries only, and as a matter of fact, I read a book that suggests the same (didn't read it any further, the code was a bit challenging). I'll read all of the posting again, but I still wanted to post what I have done to see if you have any suggestions. Thanks!
0
 
horaliaAuthor Commented:
OK, I read one of your postings where you suggested to "include" the file where I have all the queries and the compiled variables. Let me do this and see if it works for me.... In this new case, where I want to include two buttons to view all the results or only just a partial list, would I use a button instead of a submit? Is it possible to use the submit for both buttons? How can I distinguish when a user wants to see all ads or only late ads? Well, I guess I left you with a couple of questions, now you can't say you are bored! Thanks!
0
 
soapergemCommented:
I have to be honest...I'm not entirely sure what you're asking this time, but I'm going to take a stab at it with my fingers crossed anyway. I think your question is, essentially: "How do I create two buttons in one form that do different actions?" So, I'm going to answer that question now. If I've misinterpreted your question and you really are asking something else, let me know because I'd certainly rather answer your *real* question.

How to use two buttons? Simple! Make two "submit" buttons!

<input type="submit" name="submit1" value="whatever" />
<input type="submit" name="submit2" value="whatever" />

If the user presses the first button, then $_POST['submit1'] will be set to 'whatever' and $_POST['submit2'] will not be set to anything. Vice-versa, too. Try it out!
0
 
horaliaAuthor Commented:
That easy, huh? OK, I'll give it a try! My other question was if I have a page that contains no output, only the queries, do I just post the variables between the pages? I'm going to take my lunch break, I'll work on your suggestion as soon as I come back and let you know. Thanks for all your help and suggestions!
0
 
soapergemCommented:
I assume that these queries, in particular, are either inserting new data updating existing data in your database, using the values it just got via $_POST. If you've separated the pages like this (1 = form, 2 = queries, 3 = output), then my answer is "yes"--just go ahead and do things "between" 1 & 3. Specifically, you could implement that by doing the following (using dot-dot-dot's for brevity. I think those are called ellipses).

--page1.php
...
<form method="post" action="page2.php">
...

--page2.php
<?php

//  do all the query stuff here

header('Location: http://www.domain.com/output.php');
exit;

?>

-----------------------------------------------------------------------------
(Note the space in between "Location:" and the URL of the output page.) But that isn't the only way to do it. Oftentimes, I will combine page #1 and #2 into one comprehensive page. Then it looks like this:

--page1.php (page2.php no longer needed)
<?php
if ( isset($_POST['submit']) )
{

    //  do all the query stuff here

    header('Location: http://www.domain.com/output.php');
    exit;
}
?>
...
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
...

Obviously you might do some more validation than just checking if the submit button has been pressed, but, in general, that's how I often do it. If the form has been submit, it does all its queries and then redirects to the output. But, if the submit button has *not* been pressed, it skips over that chunk of PHP in the beginning and just outputs a <form> for the user to fill out. So either way is fine, whichever you prefer.
0
 
horaliaAuthor Commented:
Actually, these are only select queries.
0
 
horaliaAuthor Commented:
I'll try your suggestion of using three pages. I like the idea because depending on what the user selects is the query that is run. I'm also doing the validation on the second page.
0
 
horaliaAuthor Commented:
I used your suggestions and created 3 pages: ad_report.php, ad_report_qrys.php and ad_report_results.php. The problem that I'm having is that the variables created on ad_report_qrys.php are not being passed on to ad_report_results.php. I added an echo line at the end of ad_report_qrys.php to double check that the queries were being run and they were. I also created a bogus variable on ad_report_results.php and the variable was displayed. Here's what I did:
....
ad_report_qrys.php
$selDate = $_POST['selDate'];
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$periodName = $_POST['periodname'];
$pstartDate = $_POST['pstartdate'];
$pendDate = $_POST['penddate'];

-checked parameters
-created the queries and ran them.
-assigned query results to two variables:
//Fetch query results
while($row = mysql_fetch_array($resultNew))
      $NewAds = $row[0];
while($row = mysql_fetch_array($resultLate))
      $LateAds = $row[0];
-added location line you suggested:
header('Location:./ad_report_results.php');
exit;
.....
ad_report_results.php
-added the following code to display the variables:
<?php

echo $NewAds;
echo $LateAds;

?>
.....

I didn't detail ad_report.php since the variables from this page are being passed correctly. What can I be doing wrong?
0
 
soapergemCommented:
When I made my suggestion of using three pages, I made it because I assumed that you were simply doing INSERT or UPDATE queries (not SELECT) queries. If that's all you're doing, the pages should not really be separated in quite the way you have them now. SELECT queries are usually done directly in a page displaying data, or in a second page that is include()'ed by the first. From what I can infer from your code, I think your pages are set up like this:

1. ad_report.php  --> this contains the following line somewhere:
      <form action="ad_report_qrys.php" method="post">

2. ad_report_qrys.php  --> this executes queries based on the POST data it has just received

3. ad_report_results.php  --> this (probably) contains the following line somewhere:
      include('ad_report_qrys.php');

Please correct me wherever I'm wrong. The problem is that the $_POST variables rarely exist. Once you press the "submit" button and it takes you to ad_report_qrys.php (if only for a split-second), this page has all the data stored conveniently in the $_POST variables. It executes its queries successfully, as you pointed out. But then you redirect to ad_report_results.php, and the very instant you leave this page, all of the $_POST data is deleted automatically. That's really where the problem comes from. $_POST data are very transient; they only exist *immediately* after a <form> has been submitted--and only inside that single page. What that means is that if you are doing INSERT or UPDATE queries, this redirect-schema is perfect, because you want any particular INSERT/UPDATE queries to run only once. SELECT queries, however, are a completely different story.

For brevity, I am going to use these conventions:

ad_report.php is hereby known as "page 1"
ad_report_qrys.php is hereby known as "page 2"
ad_report_results.php is hereby known as "page 3"

-------------------------------------------------------------------------------------------
Here's what you need to do:

1. Have the <form> in page 1 send its action to page 3 (instead of 2).

2. Update page 2 (ad_report_qrys.php) to look like this:
<?php
-checked parameters
-created the queries and ran them.
-assigned query results to two variables:
//Fetch query results
while($row = mysql_fetch_array($resultNew))
     $NewAds = $row[0];
while($row = mysql_fetch_array($resultLate))
     $LateAds = $row[0];
...
?>

3. Update page 3 (ad_report_results.php) to look like this:
<?php

// page 1 now sends its $_POST variables here
$selDate = $_POST['selDate'];
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$periodName = $_POST['periodname'];
$pstartDate = $_POST['pstartdate'];
$pendDate = $_POST['penddate'];

include('./ad_report_qrys.php');

// because of the include() statement, the following variables now exist:
echo $NewAds;
echo $LateAds;

?>

Notice that I moved some of the code you had in page 2 to page 3 (the part about the $_POST vars). This wasn't entirely necessary, but it's cleaner that way and better explains what is going on. Page 3 receives the <form> data from page 1, and stores it in some variables. Then it includes page 2. This means that in page 2, you can automatically assume that these variables already exist (since they're in page 1). Page 2 uses these variables to run some queries, and compiles some new variables. These variables are still accessible from page 3 because we used the include() statement. Finally, page 3 outputs these variables.
0
 
horaliaAuthor Commented:
Worked beautifully! I'm probably going to need more help with another task that I'm trying to accomplish, but I'll post another question. You've already helped me a lot with this and you deserve all the points. What I want to do is have another button appear in case there are ads to be displayed for the selected date, but I would like the table details to display on another page. I'm sure that after reading my code  you already found out that this code only displays the amount of new ads and the amount of late ads there are for the chosen date. Now what I would like to do is have the user choose if he/she wants to look at the table, instead of only the amount. I'll close out this question and award you the points. If I could, I would give you more. There are not many experts out there that are sooooo patient like you are!  Please be sure to take a look at my next question! Thanks! ;-)
0
 
soapergemCommented:
Thank you! =)
0
 
horaliaAuthor Commented:
Like I said, I'm already having problems with my other task. I'll create the question...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 15
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now