usman07 Posted May 4, 2012 Share Posted May 4, 2012 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"; } ?> Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 You have echo "<a href="xxxx.com"><img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'></a><br />"; What do you mean their own unique link Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 That will just have the same link on all the results, but I need the different images to have different links? Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 4, 2012 Share Posted May 4, 2012 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 Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Hi mate, I dont know much about PHP coding, could you break a down a little more? appreciate it. Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 4, 2012 Share Posted May 4, 2012 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 ?> Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 4, 2012 Share Posted May 4, 2012 if each link has the unique property id corresponding to the image, then yes. Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Thanks mate, where would the link be placed, for each image, in the database? Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 4, 2012 Share Posted May 4, 2012 no, it will be where you want to display the images so the user can make their choice Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 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 ?> Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Just another thing, I don't want the links to be displayed on the page, I just want the images to be links, so if the users click a image it will take them to another page. Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 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 />'; } Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 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 /> Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 here is a screenshot of my database: So here is the 'images' table, Could I add a field called 'url' or something then add the url in that field then somehow code it in php? Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 here is a screenshot of my database: So here is the 'images' table, Could I add a field called 'url' or something then add the url in that field then somehow code it in php? Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 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 />'; Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 but in my catagories i have types of property 'house' 'flat' There a image here showing you. Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Could I put property id? because each property has its own unique id? Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 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 />'; Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 So now I have a url field in the images table, yeah the id is auto_increment. Quote Link to comment Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Does that look right? Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 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 />'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.