litebearer Posted May 5, 2012 Share Posted May 5, 2012 I flipped the closing tag <?php /* put your database connection here */ $query = "SELECT * FROM images"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343270 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 What am i doing wrong here, it says 'Parse error: syntax error, unexpected ',' in /home/a2221438/public_html/test.php on line 2' Â Heres the code: <?php ('__HOST', ''); //localhost = database host name (normaly this won't need changing) ('__USER', '');Â Â //xxx = database username ('__PASS', '');Â Â //xxx = database password ('__DEF_DB', ''); //xxx = database name $query = "SELECT * FROM images"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php } ?> Â Thanks Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343271 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Sorry ignore the above post, yeah I have done it and it shows the image but when I click it, it gives me a error page.  check the link here: http://www.mumtazproperties.hostei.com/test.php  Its weird cuz when I click the browser i see the correct link appear in the web address but then quickly changes and goes to the error page as though the page is not recognised.  And in the web browser source it shows this: <a href="http://www.hosting24.com/"> Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343273 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 right, that actually works now, I changed the database to just the name of the page rather than the full url. but how do i add that in my insert.php page now? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343275 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 So this works in this test page here: <?php $connect = mysql_connect("","","") or die("Couldn't connect!"); mysql_select_db("") or die("Couldn't find db"); $query = "SELECT * FROM images"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php } ?> Â but doesn't work on this page where I need it to work, this is the main line here: echo "<a href=\"{$row['url']}\"><img class='image1' src=\"{$row['image_path']}\" alt=\"{$row['summary']}\"> </a> <br />"; help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343276 Share on other sites More sharing options...
floridaflatlander Posted May 5, 2012 Share Posted May 5, 2012 but doesn't work on this page where I need it to work, this is the main line here: Â Â Then go over your code(not just the echo statement) very carefully after you move it, something is missing. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343278 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 yeah but im new to php, i wouldn't know what should be where. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343279 Share on other sites More sharing options...
litebearer Posted May 5, 2012 Share Posted May 5, 2012 for the moment, replace this  echo "<a href=\"{$row['url']}\"><img class='image1' src=\"{$row['image_path']}\" alt=\"{$row['summary']}\"> </a> <br />";  with this...  ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343311 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Iv done that and replaced the code with <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php But it still does the same thing for some odd reason? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343320 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 There must be something wrong with the code, i really don't understand why it doesn't seem to work. here is all the php code on the page: <?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 "<a href=\"{$row['url']}\"><img class='image1' src=\"{$row['image_path']}\" alt=\"{$row['summary']}\"> </a> <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"; } ?> Â This beginning line of this code is the one that doesn't seem to work (the url of the image): echo "<a href=\"{$row['url']}\"><img class='image1' src=\"{$row['image_path']}\" alt=\"{$row['summary']}\"> </a> <br />"; Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343321 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 What is this foreach loop used for? foreach ($pVars as $k=>$v){ $v = san($v); } I don't see $v used anywhere.  What is the point of building the $pVars array when you have the $_POST array available? Seems like you've got some unneeded code in there. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343322 Share on other sites More sharing options...
litebearer Posted May 5, 2012 Share Posted May 5, 2012 Also, try this... Â replace this: $qry = $sql->sqlStart.$sql->stmt.'Group By property.id'; Â with this... $qry = $sql->sqlStart.$sql->stmt.'Group By property.id'; echo $qry; exit(); Â and tell us the results Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343323 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 That displays this on screen and the images and text is not there no more: SELECT property.id, image_path, area_name, cat_name, bedrooms, bathrooms, receptions, parking, market_type, asking_price, summary, pay_interval FROM property INNER JOIN catagorys ON property.catagory_id = catagorys.id INNER JOIN locations ON property.location_id = locations.id LEFT JOIN images ON property.id = images.property_id WHERE (location_id = '1') AND(catagory_id = '2') AND(market_type = 'rent') Group By property.id  i dont know to be honest drummin but would that have a effect on the images links? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343324 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Can you hard code the image into the results display and get an image to show? Â Modify your image path line so it duplicates this hard coded line. Â Again, can you hard code the link so it goes where you want? Â Does $row['url'] show the same? Â Seems like some simple tests are in order. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343326 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Somewhere along the line you've also lost your multiple="multiple" for the areas. Seems like a foreach loop would bring this back. Not sure if this example will work for you but something like this.  foreach ($_POST['areas'] as $location_id){ $sql->manAdd('location_id', $location_id); } Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343328 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Iv already done a test using this, and it works fine, the link takes me to the correct page. This is what I used: <?php $connect = mysql_connect("mysql10.000webhost.com","a2221438_usman","usman1") or die("Couldn't connect!"); mysql_select_db("a2221438_homes") or die("Couldn't find db"); $query = "SELECT * FROM images"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php } ?> Â and the multiple for the areas works fine mate, its hooked up with the mySQL database so when I add a new entry in there it will also be added on the page. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343329 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 That above post was when I tested it on another thing, but its still not working on the page where I want it. can anyone please assist me somehow on what it is and why it is not working? I have been on this for nearly 3 days now, just to get a link working. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343334 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Sorry ignore the above post, yeah I have done it and it shows the image but when I click it, it gives me a error page.  check the link here: http://www.mumtazproperties.hostei.com/test.php  Its weird cuz when I click the browser i see the correct link appear in the web address but then quickly changes and goes to the error page as though the page is not recognised.  And in the web browser source it shows this: <a href="http://www.hosting24.com/"> Just tested the link on this page and it took me to the http://www.mumtazproperties.hostei.com/propertyinfo.html page. Seems to be working well. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343335 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Yeah mate thats on a test page, with no other code, but when I try inserting that code in the page where I actually want it called 'insert.php'. it does not work. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343346 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Ya I was looking at your actual site just now as see what you're talking about. Are you wanting the link to go to properyinfo.php and pass the property ID to display details? OR is the "Details view" incorporated into your "insert.php" page? Something else? The link is currently going to insert.php but as far as I know, the only identifier you have is POST from your form. The property ID needs to be passed along with the link to the page where you are showing the details. A new query is made based on this ID and details are shown. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343351 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Yeah i want the page to go to the 'propertyinfo.html' page. Im not sure with all the technical way, but what I want it when viewing the website is, when your results come up, to click the image of a property then it takes you directly to that page. Â And when I view the source code in the browser it just has: href="" the href is just empty, so i dont know why that is? Â How could I get it to work? Â I thought it would be so simple, but has taken me nearly 3 days and still not working. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343355 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Well change the page to php. hard code propertyinfo.php as your link. And add a GET value for the property id, something like <a href="propertyinfo.php?id=$propertyid">  Then on propertyinfo.php pick up this GET['id'] and query to show details. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343357 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 but what i don't understand is on the test page, its all working with the page being .html and everything else, so why is it not working on the page where i want it to work? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343359 Share on other sites More sharing options...
Drummin Posted May 5, 2012 Share Posted May 5, 2012 Well how are the details being called on the test page propertyinfo.html? Must be hard coded. You need to make it dynamic so it will show whatever property is selected. This entails making propertyinfo a php page, somehow passing the property ID to this page (via GET) and doing a DB query. As I assume insert.php will show a bunch of properties, the best way I can think of is hard coding the link as I explained and passing the ID. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343364 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 The details are being called to the test page like this and iv tried using the same method to the page I want it in but the same problem still remains: <?php $connect = mysql_connect("","","") or die("Couldn't connect!"); mysql_select_db("") or die("Couldn't find db"); $query = "SELECT * FROM images"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { ?> <a href="<?php echo $row['url']; ?>"><img src="<?php echo $row['image_path']; ?>" alt=""></a><hr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/3/#findComment-1343367 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.