...

View Full Version : Need Help Creating Picture Link to Picture in Mysql



Bozo
09-11-2011, 04:29 PM
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]

tladyman
09-11-2011, 07:21 PM
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)

BluePanther
09-11-2011, 07:29 PM
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]


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.


$var = 'Foo';
echo "$var bar"; // Will echo Foo bar
echo '$var bar'; // Will echo $var bar

Your code with different quotation marks:

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

Bozo
09-11-2011, 10:52 PM
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:


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> ";

BluePanther
09-11-2011, 11:17 PM
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:


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>";


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

Bozo
09-12-2011, 12:29 AM
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:

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>";

BluePanther
09-12-2011, 12:40 AM
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:

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>";


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.

tangoforce
09-12-2011, 12:53 AM
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.

Bozo
09-12-2011, 12:58 AM
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

BluePanther
09-12-2011, 01:03 AM
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 :).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum