Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Need Help Creating Picture Link to Picture in Mysql

    Hi,

    I am new to this form and also fairly new to PHP. I was wondering if anyone could help me with the following code? I have pictures stored in MySQL and would like to display thumbnails that are linked to themselves in the database. I have everything working except the link. Any help would be greatly appreciated.

    Bozo


    [CODE]
    echo "<a HREF= target=<img src=picscript.php?imname=".substr($row[ImageName], 0, -4)."><img src=picscript.php?imname=".substr($row[ImageName], 0, -4)." width=135 height=90 border=0 /></a> ";
    [ICODE]

  • #2
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post
    I think you're having problems with the quotes and nofollow. Try it like this:
    \"nofollow\"

    EDIT: (can't use code tags, something funny happens with the slashes)
    Last edited by tladyman; 09-11-2011 at 07:23 PM.

  • Users who have thanked tladyman for this post:

    Bozo (09-11-2011)

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Bozo View Post
    Hi,

    I am new to this form and also fairly new to PHP. I was wondering if anyone could help me with the following code? I have pictures stored in MySQL and would like to display thumbnails that are linked to themselves in the database. I have everything working except the link. Any help would be greatly appreciated.

    Bozo


    [CODE]
    echo "<a HREF= target=<img src=picscript.php?imname=".substr($row[ImageName], 0, -4)."><img src=picscript.php?imname=".substr($row[ImageName], 0, -4)." width=135 height=90 border=0 /></a> ";
    [ICODE]
    Quote Originally Posted by tladyman View Post
    I think you're having problems with the quotes and nofollow. Try it like this:
    \"nofollow\"

    EDIT: (can't use code tags, something funny happens with the slashes)
    Yeah your quotes are the problem. You're escaping the string too early which will flag a fatal error.
    Consider your quotation marks carefully. In your case, using ' to encapsulate what you want to echo will work out much better for you. " makes php look for variables inside the quotation marks, whereas ' will treat it as pure text.
    PHP Code:
    $var 'Foo';
    echo 
    "$var bar"// Will echo Foo bar
    echo '$var bar'// Will echo $var bar 
    Your code with different quotation marks:
    Edit:
    Removed code. When I started editing it I noticed it was all over the place. You have no href, and you're setting your target to an img tag. That can't be done. a tags should take the form of <a href="location.jpg"><img /></a>.

    Note: use PHP tags when posting PHP code :P

  • Users who have thanked BluePanther for this post:

    Bozo (09-11-2011)

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thank you everyone for your assistance in this. I was able to figure out what was wrong. The following worked great. Now all I have to do is find a way to reduce the image sizes as it is causing by browser to crash sometimes now. I believe the amount of data is the problem.

    Bozo

    Here was the solution:

    Code:
    echo "<a HREF=picscript.php?imname=".substr($row[ImageName],0, -4)."><img src=picscript.php?imname=".substr($row[ImageName], 0, -4)." width=135 height=90 border=0 /></a> ";

  • #5
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    I hate to burst your bubble, but you've kind of ignored all I said about quotation marks and your html itself is invalid.

    Attributes should be encapsulated in " marks. Anything else is wrong. It might also be the reason your browsers are having a hard time. Your code with my revisions:
    Code:
    echo '<a href="picscript.php?imname='.substr($row[ImageName],0, -4).'"><img src="picscript.php?imname='.substr($row[ImageName], 0, -4).'" width="135" height="90" border="0" /></a>";
    Edit: Please read my previous replies for an explanation as to why this is more correct. Also, for some reason this forum is filtering a ' from behind the " before the width attribute. Had to use code tags instead
    Last edited by BluePanther; 09-11-2011 at 11:22 PM.

  • Users who have thanked BluePanther for this post:

    Bozo (09-12-2011)

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    6
    Thanked 0 Times in 0 Posts
    BluePanther;

    Sorry if you fell I totally ignored your comment, but I had found the solution prior to your post. When I tried your last post. The code failed, where the code I posted worked fine. If you were in the same position, which code would you use?

    Bozo

    Your code was:
    Code:
    echo '<a href="picscript.php?imname='.substr($row[ImageName],0, -4).'"><img src="picscript.php?imname='.substr($row[ImageName], 0, -4).'" width="135" height="90" border="0" /></a>";

  • #7
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Bozo View Post
    BluePanther;

    Sorry if you fell I totally ignored your comment, but I had found the solution prior to your post. When I tried your last post. The code failed, where the code I posted worked fine. If you were in the same position, which code would you use?

    Bozo

    Your code was:
    Code:
    echo '<a href="picscript.php?imname='.substr($row[ImageName],0, -4).'"><img src="picscript.php?imname='.substr($row[ImageName], 0, -4).'" width="135" height="90" border="0" /></a>";
    Code:
    echo '<a href="picscript.php?imname='.substr($row[ImageName],0, -4).'"><img src="picscript.php?imname='.substr($row[ImageName], 0, -4).'" width="135" height="90" border="0" /></a>';
    That will work. I forgot to change the last " to a '. The actual PHP use of quotation marks isn't entirely important for small projects, but it's just good practise. However, the html layout is important, which was incorrect in your solution. It might have looked ok in the browser, but the html was invalid. Use my code and see what browser performance is like. It's only a hunch I have that the incorrect html is slowing the browser down significantly.

  • Users who have thanked BluePanther for this post:

    Bozo (09-12-2011)

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Just to chime in and say that if you need help understanding the correct use of quotes, I have a TIP in my signature about quotes.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Bozo (09-12-2011)

  • #9
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    6
    Thanked 0 Times in 0 Posts
    BluePanther,

    That worked great that time, thank you very much for bearing with me on this. As I mentiond, I am new to PHP, but have been coding other languages for years, so if something works it's hard for me to understand why I should change it.

    Tangoforce,

    Thank you for the tip also. This appears to be a really good forum with some very good solutions. I am glad I tried this one. I usually just keep hitting Google for solutions.

    Bozo

  • #10
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Bozo View Post
    BluePanther,

    That worked great that time, thank you very much for bearing with me on this. As I mentiond, I am new to PHP, but have been coding other languages for years, so if something works it's hard for me to understand why I should change it.

    Tangoforce,

    Thank you for the tip also. This appears to be a really good forum with some very good solutions. I am glad I tried this one. I usually just keep hitting Google for solutions.

    Bozo
    No bother at all . Tangoforce's signature will explain more about the quotes like he said .

  • Users who have thanked BluePanther for this post:

    Bozo (09-12-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •