Page 1 of 1

Problems with passing variables to pages2 + on search result

Posted: Wed May 28, 2003 11:15 am
by markbm
I am having an issue whereby I am not able to get the variables back on pages 2 + for
a search results page that I have built. Basically, I have a search form page, which POSTs the
variables that are used to build my mySQL WHERE statement. The below page (which is the
search results page) works perfectly on page 1...in all cases. However, when clicking a link to go to
successive pages and/or PREV and/or NEXT...the variables are not passed and my sql statement changes
from, for example,

query_where= "where HEAT_SQ_FT >= 0 AND HEAT_SQ_FT <= 9999 AND HPG_PLAN_ID like '%-1%' AND ACTIVE=1 order
by HEAT_SQ_FT DESC"

to

query_where= "where HEAT_SQ_FT >= 0 AND HEAT_SQ_FT <= 9999 AND ACTIVE=1 order by HEAT_SQ_FT DESC"

In essence, the "passed" variables are not retained for inclusion in the select on successive pages.

It does seem to work, on successive pages, when I only pass the HEAT_SQ_FT TO and FROM information, but
not if I add any other variables...

Any ideas would be greatly appreciated. Thank you for your help.

Mark


=========================================
CODE FOR SEARCH RESULTS PAGE:

Code: Select all

<html>

<head>
<?php




//handle sq footage
if ($from <> "") {	
	$sq_ft_range = "HEAT_SQ_FT >= $from  ";
} elseif ($min_ft <> "") {
	$from = $min_ft;
	$sq_ft_range = "HEAT_SQ_FT >= $from ";
} else {
	$from = 0;
	$sq_ft_range = "HEAT_SQ_FT >= $from ";	
};



if ($to <> "") {	
	$sq_ft_range .= "AND HEAT_SQ_FT <= $to ";
} elseif ($max_ft <> "") {
	$to= $max_ft;
	$sq_ft_range .= "AND HEAT_SQ_FT <= $to ";
} else {
	$to = 9999;
	$sq_ft_range .= "AND HEAT_SQ_FT <= $to ";
};


if ($HEATED_SQ_FT == "" or $HEATED_SQ_FT == " " ){
	$sq_ft_range .= " ";
	
} else {
	$sq_ft_range .= "AND HEAT_SQ_FT = $HEATED_SQ_FT ";
};


if (empty($PLAN_NUM)) {  
	$hpg_plan_search = '';
} else {
	$hpg_plan_search = "AND HPG_PLAN_ID like '%$PLAN_NUM%'";
};

//beds from

if ($Beds_From == "Select" or $Beds_From == "" ) {  
	$bed_search = '';
} else {	
	$bed_search = "AND NUM_BEDROOMS >= $Beds_From ";
	
};		

//beds to
if ($Beds_To == "Select" or $Beds_To == "" ) {  
	$bedto_search = '';
} else {	
	$bedto_search = "AND NUM_BEDROOMS <= $Beds_To ";

	
};		


//bath from

if ($Baths_From == "Select" or $Baths_From == "" ) {  
	$bathfrom_search = '';
} else {	
	$bathfrom_search = "AND NUM_BATHS >= $Baths_From ";	
};	

	
//bath to
//--------------------------------------------
if ($Baths_To == "Select" or $Baths_To == "" ) {  
	$bathfrom_search = '';
} else {
	$bathto_search = "AND NUM_BATHS <= $Baths_To ";
	
};		


//number of floors
//--------------------------------------------
if ($levels == "" or $levels == " " ) {  
	$levels_where = '';
} else {
	$levels_where = "AND NUM_FLOORS = $levels ";
		
};	


          $pagename= "PlanSearch";
          //include files
          include("includes/title.php");
         // printf("<TITLE>$title_prefix $pagename=$from-$to</TITLE>");
          include("includes/META.html");


 ?> 

</head>



<BODY  background=main_files/background.gif class=ltBackground>



<?php


//db connections
include("includes/db.php");





 ?>
 <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=700>
  <TBODY> 
  <TR vAlign=middle> 
    <TD colspan=4 height="45">    
          <font face="Verdana, Arial, Helvetica, sans-serif">
          <?php
            printf("<font size=6 face=Verdana, Arial, Helvetica, sans-serif color=#003366>");
     	    printf("<b><SPAN class=headLrg>Search Results - <font color=#006400 size=5>$from Sq. Ft. to $to Sq. Ft.</b></font></SPAN>");
           ?>
             <img src="main_files/darkgrey_bar.gif"  height="38">  
</font>    </TD>
  </TR>
  <TR> 
      <TD vAlign=middle colspan=4>    
     <font face="Verdana, Arial, Helvetica, sans-serif">
     <br>text goes here
 
   
         
  <?php
  


  if ($to == 9999) {
  printf("<br><br>");	
  };
  
     //Next / Previous links
function pagenav() {
    global $limit,$offset,$numpage,$where, $from, $to;
    if ($where) {
    	
        $safewhere=urlencode($where);      
      
    }
 echo "<center>";
        if ($offset>=$limit) {
            $newoff=$offset-$limit;
            
            echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere">
            <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>PREV</font></A>";
              
        }; 
         echo "&nbsp;";
     

        for ($i=1;$i<=$numpage;$i++) {
            if ((($i-1)*$limit)==$offset) {
                print "$i ";
            } else {
                $newoff=($i-1)*$limit;

                echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere">
                <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>$i</font></A> ";
            }
        }
         echo "&nbsp;";
      
        if ($offset!=$limit*($numpage-1)) {
            $newoff=$offset+$limit;
            echo ("<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere">");
            echo ("<font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue> NEXT</font></A><br>");
            
        };
         printf("<a href=plan_sizes.php><FONT COLOR=BLUE>[BACK TO SEARCH]</FONT></a><br><br></td>");
   echo "</center>";   
 
} // END FUNCTION


// set this to the number of results you wish on each page
$limit=8; 

// if no offset has been passed, offset should be 0
if (!$offset) $offset=0; 

if (!$where) {
    if (empty($one) || empty($two)) {
        // some error handling as $one and/or 
        //$two not passed to initial page
    }
    $where="$one|$two";
}

    
// NOTE: if a pipe (|) may be in the value 
// of $one or $two, use a different delimiter
$data=explode('|',$where);

$query_where= " where $sq_ft_range $hpg_plan_search $bed_search $bedto_search $bathfrom_search $bathto_search $levels_where AND ACTIVE=1 order by HEAT_SQ_FT DESC ";


$result=mysql_query("select count(*) from PRODUCTS $query_where");

list($numrec)=mysql_fetch_row($result);

#calc num pages
$numpage=intval($numrec/$limit);

if ($numrec%$limit) {
    $numpage++; // add one page if remainder
}

//<!-- result display loop -->
 
if ($numpage>1) {
  //  print "<br>";
    pagenav();
    print "<P>";
} 
    
?>
  
    </td>
  </tr>
  <tr bgcolor=#003366>
  <td vAlign=middle colspan=4>       
            <font face="Verdana, Arial, Helvetica, sans-serif size="4" color="#ffffff"><br><b>Click on the "Plan #" 
              or home rendering to view more detailed information about the plan: </b></font><br><br>
  </td>
  </tr>
  
    
 <?php 


$result=mysql_query ("select * from PRODUCTS $query_where limit $offset,$limit");

if ($numrec > 0){

// Display the text of each joke in a paragraph 
 while ( $row = mysql_fetch_array($result) ) { 
 	   // Header Row //
 	   $HPG_PLAN_ID = ($row['HPG_PLAN_ID']);
 	   $designer = ($row['DESIGNER']);
	   $price_code = ($row['PRICE_CODE']);
 	   echo("<font face=Verdana, Arial, Helvetica, sans-serif size=3>");
 	   echo("<tr><td valign=top width=270 bgcolor=#EEF5FA><font size=4 face=Verdana, Arial, Helvetica, sans-serif>");
 	   echo("</font>");
 	
 	   echo("</font><br><font size=2 face=Verdana, Arial, Helvetica, sans-serif color=#006400>" . $row["PLAN_NAME"]. "</font></b><br><br>");  
 	    printf("</font><font size=2 face=Verdana, Arial, Helvetica, sans-serif color=#666666 size=1><b>Heated Sq. Ft. </b>- " . $row["HEAT_SQ_FT"]. "<br>");
          printf("<font size=2 face=Verdana, Arial, Helvetica, sans-serif ><b>Un-Heated Sq. Ft.</b> - " . $row["UNHEAT_SQ_FT"]. "</font><br>");
          printf("<font size=2 face=Verdana, Arial, Helvetica, sans-serif ><b>Total Sq. Ft. </b>- " . $row["TOTAL_SQ_FT"]. "</font></td>");
                      
          	printf("<td valign=top align=center><a href='http://www.websitename.com/index_files/prod_detail.php?planid=" . $row["HPG_PLAN_ID"] . "&designer=$designer&price_code=$price_code&disc=$disc&disc_free_2nd_ship=$disc_free_2nd_ship" . "&disc_free_stand_ship=$disc_free_stand_ship&disc_free_nextday_ship=$disc_free_nextday_ship&disc_planid=$disc_planid'>
<img src='http://www.websitename.com/index_files/main_files/$HPG_PLAN_ID/" . $row["THMBNAIL_IMG"] . "' border=0></a><br><font size=3 face=Verdana, Arial, Helvetica, sans-serif color=#666666><b>Available Foundation Types:</b><br>" . $row["FOUNDATION"] . "</font><br></td>");
      
          printf("<td align=center valign=top>");
          printf("<img src=images/grey_spacer.gif border=0 ><br>");
         
          printf("<img src=images/grey_line.gif border=0><br>");
          printf("<font size=3 face=Verdana, Arial, Helvetica, sans-serif ><b># Bedrooms </b>- " . $row["NUM_BEDROOMS"]. "</font><br>");
          printf("<font size=3 face=Verdana, Arial, Helvetica, sans-serif ><b># Baths</b> - " . $row["NUM_BATHS"]. "</font><br>");
          printf("<font size=3 face=Verdana, Arial, Helvetica, sans-serif ><b>Width:</b> " . $row["WIDTH"]. "</font><br>"); 
          printf("<font size=3 face=Verdana, Arial, Helvetica, sans-serif ><b>Depth:</b> " . $row["DEPTH"]. "</font><br>"); 
          printf("<font size=3 face=Verdana, Arial, Helvetica, sans-serif ><b>Garage:</b> " . $row["GARAGE"]. "</font><br>"); 
          printf("<img src=images/grey_line.gif border=0>");
          
               
          printf("</td>");
        
          printf("</td>");
          printf ("</tr>");
          printf ("<tr bgcolor=#808080><td colspan=4>&nbsp;</td></tr>");
};

}else {
	printf("<tr><td><br><Br><font face=Verdana size=2 color=red><center><b>Your search returned 0 results...Please re-enter your criteria to broaden the search...</b></center></font><br><center><a href=plan_sizes.php><font face=Verdana size=2 color=blue>Back to Search</a><Br></td></tr>");
};
printf ("<tr align=center><td colspan=4><br>");




//<!-- HTML headers and other non-relevent stuff -->


//<!-- result display loop -->
if ($numpage>1) {
    //print "<br>";
    pagenav();
    print "<P>";
  
}

?> 

</TD>
</TR>

<tr bgcolor=#003366>
<td colspan=4>
&nbsp;
</td>
</tr>

<tr>
<td colspan=4>
<Br>
  <?php
          //include files
          include("includes/footer.php");
          
         
          ?>
</td>
</tr>

 </table>
</body>
</html>
mod_edit: added

Code: Select all

tags and a string concat (to enable a line break within the M-m-m-monsterlink )[/size]

Posted: Wed May 28, 2003 1:04 pm
by volka
those values like $Beds_From ...where do they come from?

Posted: Wed May 28, 2003 1:32 pm
by markbm
These are POSTed values from my search form.....basically when I submit the search form...on a separate page....these variables hold the values from those fields on the search form. Each of these variables will be something like 1, 2, 3, etc. At the top of this search results page, I evaluate each of those fields (i.e. variables) being passed over from the search form...and create a new variable holding the mySQL select syntax for inclusion in my $query_where statement when pulls up all the results.

These variables are just not being passed to subsequent pages, even if I add them to the URL string in the function (as such):

Code: Select all

//Next / Previous links
function pagenav() {
    global $limit,$offset,$numpage,$where, $from, $to;
    if ($where) {
    	
        $safewhere=urlencode($where);
        
        if ($gonethru == 1){
        	$safewhere=$getvars;
       
       	};
        
        //$safewhere=$query_where;
    }
 echo "<center>";
        if ($offset>=$limit) {
            $newoff=$offset-$limit;
            
            echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">
            <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>PREV</font></A>";
               // </TD>";
        }; 
         echo "&nbsp;";
     

        for ($i=1;$i<=$numpage;$i++) {
            if ((($i-1)*$limit)==$offset) {
                print "$i ";
            } else {
                $newoff=($i-1)*$limit;

                echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">
                <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>$i</font></A> ";
            }
        }
         echo "&nbsp;";
      
        if ($offset!=$limit*($numpage-1)) {
            $newoff=$offset+$limit;
            echo ("<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">");
            echo ("<font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue> NEXT</font></A><br>");
            //printf("<a href=http://www.website.com/index_files/plan_sizes.php><img src=images/backtosearch.gif border=0></a><br>");
            //echo (" <br>");
        };
         printf("<a href=http://www.website.com/index_files/plan_sizes.php><FONT COLOR=BLUE>[BACK TO SEARCH]</FONT></a><br><br></td>");
   echo "</center>";   
 
} // END FUNCTION
mod_edit: added

Code: Select all

tags[/size]

=============================

Thank you for your help.

Mark

Posted: Wed May 28, 2003 1:41 pm
by volka
do those parameters appear (correctly) in the prev/next-url ?
They're not mentioned in
global $limit,$offset,$numpage,$where, $from, $to;
p.s.: please use the

Code: Select all

-tags to post php-script code.[/size]

Posted: Wed May 28, 2003 2:41 pm
by markbm
I added those parameters:

====================
global $limit,$offset,$numpage,$where, $from, $to, $hpg_plan_search, $bed_search, $bedto_search, $bathfrom_search, $bathto_search, $levels_where;
========================
and it appears as though the same issue is occuring..variable names occur in url but no values for those....

Thanks again..

Mark

Posted: Wed May 28, 2003 2:45 pm
by nielsene
Isn't this just register_globals all over again? Try using $_POST["bed_search"], etc...

Posted: Wed May 28, 2003 3:08 pm
by volka
as far as I understood the script works the first time it is invoked but does not pass the parameters to itself via the prev/next links. So register_globals is probably enabled.
but you have to propagte the parameter $Beds_From, not $bed_search because it's overwritten by
if ($Beds_From == "Select" or $Beds_From == "" ) {
$bed_search = '';
} else {
$bed_search = "AND NUM_BEDROOMS >= $Beds_From ";

}
in the next request ($bed_search is only an example)

Posted: Wed May 28, 2003 3:17 pm
by markbm
Thanks for the note. I checked and my register_globals is set to "On". Also, I added the $_POST statements that you mentioned and added these in the globals def. and in the hyperlinks for the next/previous/page numbers. When I run, I still seem to get the same issue whereby the variables are blank..

Thanks for your help, and please let me know any other ideas that you might have. I very much appreciate it.

Mark


===================================

Code: Select all

$_POST["hpg_plan_search"];
	$_POST["bed_search"];
	$_POST["bedto_search"];
	$_POST["bathfrom_search"];
	$_POST["bathto_search"];
	$_POST["levels_where"];
   

  if ($to == 9999) {
  printf("<br><br>");	
  };
  
     //Next / Previous links
function pagenav() {
    global $limit,$offset,$numpage,$where, $from, $to, $hpg_plan_search, $bed_search, $bedto_search, $bathfrom_search, $bathto_search, $levels_where;
    if ($where) {
    	
        $safewhere=urlencode($where);
        
        if ($gonethru == 1){
        	$safewhere=$getvars;
       
       	};
        
        //$safewhere=$query_where;
    }
 echo "<center>";
        if ($offset>=$limit) {
            $newoff=$offset-$limit;
            
            echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">
            <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>PREV</font></A>";
               // </TD>";
        }; 
         echo "&nbsp;";
     

        for ($i=1;$i<=$numpage;$i++) {
            if ((($i-1)*$limit)==$offset) {
                print "$i ";
            } else {
                $newoff=($i-1)*$limit;

                echo "<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">
                <font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue>$i</font></A> ";
            }
        }
         echo "&nbsp;";
      
        if ($offset!=$limit*($numpage-1)) {
            $newoff=$offset+$limit;
            echo ("<A HREF="$PHP_SELF?from=$from&to=$to&offset=$newoff&where=$safewhere&hpg_plan_search=$hpg_plan_search&bed_search=$bed_search&bedto_search=$bedto_search&bathfrom_search=$bathfrom_search&bathto_search=$bathto_search&levels_where=$levels_where">");
            echo ("<font size=3 face=Verdana, Arial, Helvetica, sans-serif color=blue> NEXT</font></A><br>");
            //printf("<a href=http://www.houseplangallery.com/index_files/plan_sizes.php><img src=images/backtosearch.gif border=0></a><br>");
            //echo (" <br>");
        };
         printf("<a href=http://www.houseplangallery.com/index_files/plan_sizes.php><FONT COLOR=BLUE>[BACK TO SEARCH]</FONT></a><br><br></td>");
   echo "</center>";   
 
} // END FUNCTION
mod_edit: please, use the

Code: Select all

tags[/color]

================================

Posted: Wed May 28, 2003 3:27 pm
by volka
simply writing $_POST["hpg_plan_search"]; doesn't change anything.
If you want to get your script working without register_globals you have to replace e.g. $hpg_plan_search by $_POST["hpg_plan_search"], without the quotes if you're within a literal

Code: Select all

$_POST['hpg_plan_search'] = 'anything';
// and
echo 'value of hpg_plan_search is ', $_POST['hpg_plan_search'];
// but
echo "value of hpg_plan_search is $_POST[hpg_plan_search]";
Still I think you're passing the wrong parameters. Did you check the script for that?

IT WORKED!

Posted: Wed May 28, 2003 3:28 pm
by markbm
Passing the initial variables to the second page, along with adding them to the globals definition worked on the subsequent pages!!
Thank you, each of you, for your helpful assistance. I really appreciate it.

Sometimes I get so entrenched in the details of an issue, that the more obvious solutions are harder to recognize. Thank you again for your help.

Mark