Web Analytics Made Easy -
StatCounter Need Help Creating Picture Link to Picture in Mysql - CodingForum

Announcement

Collapse
No announcement yet.

Need Help Creating Picture Link to Picture in Mysql

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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; Sep 11, 2011, 02:23 PM.
    Website

    Comment


    • #3
      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]
      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
      Useful function to retrieve difference in times
      The best PHP resource
      A good PHP FAQ
      PLEASE remember to wrap your code in [PHP] tags.
      PHP Code:
      // Replace this
      if(isset($_POST['submitButton']))
      // With this
      if(!empty($_POST))
      // Then check for values/forms. Some IE versions don't send the submit button 
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

      Comment


      • #4
        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> ";

        Comment


        • #5
          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; Sep 11, 2011, 06:22 PM.
          Useful function to retrieve difference in times
          The best PHP resource
          A good PHP FAQ
          PLEASE remember to wrap your code in [PHP] tags.
          PHP Code:
          // Replace this
          if(isset($_POST['submitButton']))
          // With this
          if(!empty($_POST))
          // Then check for values/forms. Some IE versions don't send the submit button 
          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

          Comment


          • #6
            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>";

            Comment


            • #7
              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.
              Useful function to retrieve difference in times
              The best PHP resource
              A good PHP FAQ
              PLEASE remember to wrap your code in [PHP] tags.
              PHP Code:
              // Replace this
              if(isset($_POST['submitButton']))
              // With this
              if(!empty($_POST))
              // Then check for values/forms. Some IE versions don't send the submit button 
              Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

              Comment


              • #8
                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.
                "Tango says double quotes with a single ( ' ) quote in the middle"
                '$Name says single quotes with a double ( " ) quote in the middle'
                "Tango says double quotes ( \" ) must escape a double quote"
                '$Name single quotes ( \' ) must escape a single quote'

                Comment


                • #9
                  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

                  Comment


                  • #10
                    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 .
                    Useful function to retrieve difference in times
                    The best PHP resource
                    A good PHP FAQ
                    PLEASE remember to wrap your code in [PHP] tags.
                    PHP Code:
                    // Replace this
                    if(isset($_POST['submitButton']))
                    // With this
                    if(!empty($_POST))
                    // Then check for values/forms. Some IE versions don't send the submit button 
                    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎