Jump to content

[SOLVED] dynamic sql issues, php removes part of my query when move page with pagination


pixelgirl

Recommended Posts

Hello,

 

I am trying to dynamically generate sql queries depending on what data a user enters.

 

The 'dynamic' sql sections disappear when i move to the next page. I think I know why, but am not sure of the best way to modify it to make it work properly. The issue is with the $query variable in the code below, as i think the added on variables are reset to "" when the page is changed. Does anyone know a better way of doing this (i.e. the correct way) as I am just basically doing this by guesswork, and cant find anything on the net to do with this kind of issue.

 

also, this code produces results that you can then click on for more details. I then want to go back to the list of results after looking at the more details. I am using history.go(-1) to move back to the results, but a message comes up about post data. I realise this is whats sending the data to the results page, but is there any way to get rid of it or around it?

 

Because of the post data message issue and the fact that when i move to another page the code looses variable data, is it best to do this another way? I was thinking of using sessions, but a session for each variable would amount to a lot. I really need some advice on the best way to do this!

 

Any help would be appreciated :)

 

<?php
				include 'config.php';
				include 'opendb.php';
				$horsePerPage = 5;
				$pageNumber = 1;

				$pageNumber  = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;

				$offset = ($pageNumber - 1) * $horsePerPage;
				$serial = $offset + 1;

				$minHeightH		 = $_POST["HeightH"];
				$minHeightI 	 = $_POST["HeightI"];
				$maxHeightH 	 = $_POST["HeightH2"];
				$maxHeightI 	 = $_POST["HeightI2"];
				$minPrice   	 = $_POST["txtPrice"];
				$maxPrice		 = $_POST["txtPrice2"];
				$minAgeY		 = $_POST["AgeY"]; 
				$minAgeM	 	 = $_POST["AgeM"]; 
				$maxAgeY		 = $_POST["AgeY2"];
				$maxAgeM		 = $_POST["AgeM2"];
				$SQLHeightH 	 = "";
				$SQLHeightI 	 = "";
				$SQLPrice		 = "";
				$SQLAgeY		 = "";
				$SQLAgeM		 = "";


				if ($minHeightH != "" && $maxHeightH != "")
				{
					$SQLHeight = " AND h.height BETWEEN (($minHeightH*4)+$minHeightI) and (($maxHeightH*4)+$maxHeightI)";
				}
				if ($minPrice != "" && $maxPrice != "")
				{
					$SQLPrice = " AND h.price BETWEEN $minPrice and $maxPrice";
				}
				if ($minAgeY != "" && $maxAgeY != "")
				{
					$SQLAge = " AND h.age BETWEEN (($minAgeY*12)+$minAgeM) and (($maxAgeY*12)+$maxAgeM)";
				}

				$query  = "SELECT h.horseID, h.name, h.height, floor(h.height/4) AS height_hands, (h.height -((floor(h.height/4))*4)) AS height_inches, h.breed, h.price, h.colour, h.age, h.age, floor(h.age/12) AS age_years, (h.age -((floor(h.age/12))*12)) AS age_months, h.sex, hi.thumbName
						FROM horse h, horseimages hi
						WHERE h.horseID = hi.horseID
						AND hi.thumbName is NOT NULL".$SQLHeight.$SQLPrice.$SQLAge;

				$sql = $query;

				$result = mysql_query($sql . " LIMIT $offset, $horsePerPage");

				?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.