usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 I have done this, and the page appears and when I place the cursor over the image a hand appears so it shows the image being a link, but now when I click the image, it comes up with this: echo "<a href={$row['url']}><img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'> </a> <br />"; but now when I click the image, it comes up with the message 'There was a problem etc...' from this code below. } 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 https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343063 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 Looks like you need dounle qoutes in there, you'll have to escape them. Â href=\"{$row['url']}\"Â and scr=\"xxxx\"Â and alt=\"xxxx\" Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343065 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Thats to weird, I added the quotation marks: "<a href='{$row['url']}'><img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'> </a> <br />"; I can see that the image is now a link but it just doesn't take me to the page that its meant to with the link in the database. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343073 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 I don't see any added and escaped quotation marks  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/2/#findComment-1343078 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Adding the escaped quotations makes my image disappear a blue sqaure question mark appears. this is what I have: 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/2/#findComment-1343081 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 You add double quotes for the html not php and you have to escape them for php, your going to have to play with it but basiclly  so it would be something like href=\"{$row['url']}\" and the same for src and alt  I use single quotes so echo '<a href='.$row['url'].'></a>';  Like I said, play with it. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343082 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 But do you think this is the reason, why the link doesn't go to the correct page, even tho the image does appear as a link? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343084 Share on other sites More sharing options...
litebearer Posted May 4, 2012 Share Posted May 4, 2012 look at the browser source code and see what it has as the link destination. post that here Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343085 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 This is what it shows in the browser source code, weirdly no link? <a href=\'\'><img class='image1' src=\'cutouts/search/image1.png\' Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343088 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 This is what it shows in the browser source code, weirdly no link? <a href=\'\'><img class='image1' src=\'cutouts/search/image1.png\' Â So why are there single quotes and no double quotes, why are the slashes in your code? Play with it. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343094 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 I don't think it is that, the url for some reason is not showing in my source code when viewing in the browser, why is this? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343096 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 Were is you destination file, it's not here <a href=\'\'>. This should be something like <a href="http:\\www.webpage.com" >. have you named columns correctly? Â Put the echo statement you're using now on here. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343104 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 my echo statement: echo "<a href=\'{$row['url']}\'><img class='image1' src=\'{$row['image_path']}\' alt=\'{$row['summary']}\'> </a> <br />"; The PHP code above is meant to get the url from the database right, from the field name 'url'?  Should the url be from my web directory or the actually website website, iv tried both and still does not work.  Image of my database which includes |id|property id|image_path|url  Why is it 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/2/#findComment-1343110 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 Try  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/2/#findComment-1343115 Share on other sites More sharing options...
Jessica Posted May 4, 2012 Share Posted May 4, 2012 what is your SQL? before you echo this try print_r($row) and see what it contains Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343116 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 floridaflatander: that still doesn't work  jesirose: Where would i put 'print_r($row)? and i'm using phpmyadmin Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343125 Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 You were using the table called `property`for this info and another table `images` for the property image. I don't see where these tables are defined in your code on the first post. Maybe I missed it. Are you using a different table structure now? Are you actually getting results with $row? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343126 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 Yeah mate i'm using a different table structure, yeah i'm getting all the results. The image has turned into a link but the link does not go to where I want it to go. And I have the url link in my database. Â Here's the full code of echo's: $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"; } Â So when I click the link of the image, it echo's this: 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 https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343127 Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 I think those attributes should be in full quotes, escaped if needed for the line. 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/2/#findComment-1343138 Share on other sites More sharing options...
usman07 Posted May 4, 2012 Author Share Posted May 4, 2012 I just tried that mate, still getting the same problem. When I click the image it echoes this: 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 https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343142 Share on other sites More sharing options...
floridaflatlander Posted May 4, 2012 Share Posted May 4, 2012 Look at the source code and see what it has "or doesn't have" as a link for the image. Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343145 Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 Well that else statement matches up with the line if(isset($_POST['submit'])){ Â So the question then is do you have a input in your form named 'submit'? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343151 Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 ...so query is not being done, thus empty 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/2/#findComment-1343156 Share on other sites More sharing options...
litebearer Posted May 5, 2012 Share Posted May 5, 2012 Save this as test.php (make sure to include your database connection) then point your browser to it <?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/2/#findComment-1343206 Share on other sites More sharing options...
usman07 Posted May 5, 2012 Author Share Posted May 5, 2012 Yeah I have a input in my form named submit, and litebearer that code has some error in their? Quote Link to comment https://forums.phpfreaks.com/topic/262064-how-to-make-a-image-a-link-when-it-is-outputted-using-php/page/2/#findComment-1343263 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.