Jump to content

Recommended Posts

I basically have a PHP Search Form, and when a user fills in a form it outputs the results. Each result displays a image of a property, how could i make them images have their own unique link which will take them directly to the page of the property being shown?

 

Im using PHP and mySQL tables

 

Any help is appreciated,

 

Thank You.

 

Heres the PHP that outputs the results:


<?php
require_once 'mstr_ref.php';
function san($input){
if(get_magic_quotes_gpc()){
	$input=stripcslashes($input);
}
$output = mysql_real_escape_string($input);
return $output;
}
if(isset($_POST['submit'])){
$pVars = array('area'=>$_POST['areas'], 'propType'=>$_POST['prop_type'], 'saleType'=>$_POST['ptype'], 'minB'=>$_POST['min_bedrooms'], 'maxB'=>$_POST['max_bedrooms'], 'minP'=>$_POST['min_price'], 'maxP'=>$_POST['max_price']);
foreach ($pVars as $k=>$v){
	$v = san($v);
}
$sql = new makeQuery();
$sql->manAdd('location_id', $pVars['area']);
if($pVars['propType'] != 'Any'){
	$sql->manAdd('catagory_id', $pVars['propType']);
}
if ($pVars['maxB'] > 0){
	$sql->manAdd('bedrooms', $pVars['maxB'], '<=');
}
if($pVars['minB'] > 0){
	$sql->manAdd('bedrooms',$pVars['minB'],'>=');
}
if($pVars['saleType'] != 'Any'){
	if($pVars['saleType'] == "forsale"){
		$sql->manAdd('market_type', 'sale');
		if($pVars['minP'] != 0){
			$pVars['minP'] = $pVars['minP'] * 1000;
		}
		if($pVars['maxP'] != 0){
			$pVars['maxP'] = $pVars['maxP'] * 1000;
		}
	}
	if($pVars['saleType'] == 'forrent'){
		$sql->manAdd('market_type', 'rent');
	}
}

$qry = $sql->sqlStart.$sql->stmt.'Group By property.id';
$results = mysql_query($qry) or die (mysql_error()."<br />|-|-|-|-|-|-|-|-|-|-|-|-<br />$qry");
if(mysql_num_rows($results) < 1){
	die ("Sorry, No Results Match Your Search.");
}
while($row = mysql_fetch_assoc($results)){
	echo '<div class="container" style="float:left;">';
	echo '<div class="imageholder" style="float:left;">';
	echo "<img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'> <br />";
	echo '</div>';
	echo '<div class="textholder" style="font-family:helvetica; font-size:14px; float:left; padding-top:10px;">';
	echo "{$row['summary']}";
	echo "<span style=\"color:#63be21;\"><br><br><b>{$row['bedrooms']} bedroom(s) {$row['bathrooms']} bathroom(s) {$row['receptions']} reception room(s)</b></span>";
	if($row['parking'] != null){
		echo "<span style=\"color:#63be21;\"><b> {$row['parking']} parking space(s)</b></span>";
	}

	echo '</div>';
	echo '<div style="clear:both"></div>';
}

}
else{
echo "There was a problem, please click<a href='index.php'> Here </a>to return to the main page and try again";
}
?>

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

I mean when the results are displayed, they all will be different results on different properties. I have 9 properties on the website, therefore each property will have its own unique link to take them directly to the page that displays more information about the property.

Rough overview...

 

1. make each link to view.php passing  property id via url

 

2. make view.php page that: A) $_GET the id being passed; B) queries the db for that particular id; C) Displays the query results

 

echo "<a href='view.php?id=" . $row['id'] . "><img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'></a> <br />";

view.php
<?php
GET the id
connect to db
query db for that paticular id
display the results
?>

So this will let me add different links on the different images of the properties?

 

Because I don't want anything to be displayed, Once the search results are displayed depending on the search made, I want the images to have their own unique links that will take them directly to the selected property page.

Oh ok mate, i will give it a try and see what happens,

 

here what i have:

<?php
GET the id
define('__HOST', ''); //localhost = database host name (normaly this won't need changing)
define('__USER', '');    //xxx = database username
define('__PASS', '');    //xxx = database password
define('__DEF_DB', ''); //xxx = database name
query db for that paticular id
display the results
?>

 

Say you have a category table that has all your cats info including a column for the image location, we'll call it image_path.

 

run a sql statement to display the categories image_path and cat_id

 

while (this stuff) {

echo  '<a href="xxxx.com/category.php?cat='.$row['cat_id'].'"><img class="image1" src="'.$row['image_path'].' alt='.$row['summary'].'></a><br />';

}

Thanks for your assistance. Im a little bit confused, so do I create a field in my mySQL database and place the 'id' and the link then do the code you said?

echo  '<a href="xxxx.com/category.php?cat='.$row['cat_id'].'"><img class="image1" src="'.$row['image_path'].' alt='.$row['summary'].'></a><br />';
}

 

What would I put in "xxxx.com" because the links are going to all be different depending on which image is displayed.

What would I put in "xxxx.com" because the links are going to all be different depending on which image is displayed.

 

I was assuming you have a table like

 

cat_id | cat_name | summary | image_name |

1 | dogs | dogs are great |dogpic.jpg

2 | cat | cats are better | catpic.jpg

 

so xxxx.com/category.php?cat='.$row['cat_id']. would become  xxxx.com/category.php?cat=1 and it would be a picture of a dog and a link to the dog category.

 

 

It would look more like this if I did it

 

echo  '<a href="xxxx.com/category.php?cat='.$row['cat_id'].'"><img class="image1" src="/image-folder-path/'.$row['image_name'].'" alt='.$row['summary'].'></a><br />';

 

and your source would end up like this

 

<a href="xxxx.com/category.php?cat=1"><img class="image1" src="/image-folder-path/'docpic.jpg"' alt="dogs are great"></a><br />

I see you have your full path in the table so I'd used

 

echo  '<a href="xxxx.com/category.php?cat='.$row['cat_id'].'"><img class="image1" src="'.$row['image_path'].'" alt='.$row['summary'].'></a><br />';

 

Could I put property id? because each property has its own unique id?

 

It lookes like you have two unique ids. You probably only need one.  Is id an auto_increment? Anyway as long as they're unique you can use them.

 

Okay we have

 

id | property_id | image_path

id | cat_name

 

so you could do

 

echo  '<a href="xxxx.com/category.php?cat='.$row['id or property_id'].'"><img class="image1" src="'.$row['image_path'].'" alt='.$row['cat_name or any column you want'].'></a><br />';

If I had only one pic per category I'd use something like

 

id | cat_name | image_path | url | summary or what ever  |

 

echo  '<a href="'.$row['url'].'"><img class="image1" src="'.$row['image_path'].'" alt="'.$row['cat_name/summary or any column you want'].'></a><br />';

 

or

 

echo  '<a href="'.$row['url'].'"><img class="image1" src="'.$row['image_path'].'" alt="'.$row['cat_name'].' - '.$row['summary or any column you want'].'></a><br />';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.