Forum Moderators: coopster

Message Too Old, No Replies

Need help making popup image from mysql database

mysql popup images

         

slimnutty5000

9:20 pm on Nov 1, 2006 (gmt 0)

10+ Year Member



Hi,
I am making a product catalog for a site.
Basically, i have the page calling item#, description, and UPC into a 3 column table.

What i want is one of 2 options:
1. Have the entire row be clickable that can popup the item's image calling from the mysql database.
2. Add an extra column that will have a small icon that when clicked will popup an image for that item.

I have a field for "imagePath", "imageLarge" in the database ready so i can input the url of each individual image, but just dont know the exact code to get this popup to work.

Oh yeah btw, i am using PHP

Thanks

mcibor

10:52 pm on Nov 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For popup you can use javascript,

basically, you can open a new window with href view.php?id=pic_small_2

view.php:
<?php
if(!isset($_GET['id']) ¦¦!empty($id = $_GET['id'])))
{
echo "Wrong page";
exit;
}

//here you've got id of the thumbnail (in $id)
//I would validate is somehow, eg. allow only numbers in picture name. But that depends on you.

$q = "SELECT big FROM pics WHERE small='".mysql_real_escape_string($id)."'";
//ask query, retrieve row,
$img = $result['big'];
//display it
echo "<img src=\"$img\">";
?>

I think that would be quite what you want.
PS. You can check existing galleries scripts, eg on hotscripts

Regards
Michal

slimnutty5000

3:48 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



Thanks for that. I am quite a beginner in PHP so its a little confusing to me, but ill try to work with that for now.

Actually some the things im not so sure of are:

1. "view.php?id=pic_small_2"
- (pic_small_2) Is this something that i change myself for every individual link, or can it be automatic from the databse?

2. [small='".mysql_real_escape_string($id)."'";]
- what is .mysql_real_escape_string? I dont understand what to put there.

But i did find a perfect of example of what i need, but they are in ASP:

<snipped urls>

On the first link you can see a thumbnail image that im sure is being called from the database and it links to the product detail page. I dont need it to link to a page, but just popup the large image.
OR
#2 is more of what i am looking for. As you see its a slimmer table with a "pic" icon on the far right which popups the large image. Would be even more perfect if there is a way to have the popup link on the entire row than just a small icon.

help?

Thanks

[edited by: coopster at 4:46 pm (utc) on Nov. 2, 2006]
[edit reason] sorry, no urls (TOS [webmasterworld.com]) [/edit]

slimnutty5000

4:59 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



Well since i cant even post urls to show examples maybe this will help make it a little more clear for what i want. This is the table i am currently using. You can see th php code insert i am using to call the db info. I want to either make that TR clickable to popup the image (if possible) or add another TD with a tiny clickable icon to popup the large image.


<table width="100%" border="0" cellpadding="5" cellspacing="2" class="TableContent" onmouseover="changeto(event,'#FFF887')" onmouseout="changeback(event,'#FFFFFF')">
<tr>
<td width="15%" class="TableHeader">TNT ITEM # </td>
<td width="57%" class="TableHeader">DESCRIPTION</td>
<td class="TableHeader">UPC # </td>
</tr>
<?php do {?>
<tr bgcolor="#FFFFFF">
<td><?php echo $row_littletree['itemNumber'];?></td>
<td><?php echo $row_littletree['name'];?></td>
<td><?php echo $row_littletree['UPC'];?></td>
</tr>
<?php } while ($row_littletree = mysql_fetch_assoc($littletree));?>
</table>

mcibor

11:12 pm on Nov 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. to make a row clickable:

<tr onclick="window.location.href='http://www.example.com';"><td>...</td></tr>

if it doesn't work put the onclick into every <td

2.
pic_small_2 is a value from db from sell thumbnail - it is populated from db.

3.
[url=www.php.net/mysql_real_escape_string]mysql_real_escape_string[/url] is a function that escapes all data passed to database for security issues.

Let's imagine that you run a query:
$id = $_GET['id'];
SELECT * FROM `table` WHERE id = '$id'; //should return 1 row

let's imagine that $id is:
1' OR id > '0

Then you have got a query:
SELECT * FROM `table` WHERE id = '1' OR id > '0'; // returns all rows

not exactly what you expected - and possibly a security breach.
However if you do
$id = mysql_real_escape_string($_GET['id']);
SELECT * FROM `table` WHERE id = '$id'; // returns all rows or none.

Hope this answers all your questions
Michal

eelixduppy

11:22 pm on Nov 2, 2006 (gmt 0)



This type of attack is known as SQL Injection [us2.php.net]

For further information don't hesitate to go to the documentation: mysql_real_escape_string [us2.php.net]
;)

slimnutty5000

11:48 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



Thanks for all the help, but i think what i want is a lot simpler than you guys are making it out to be. I just dont know enough PHP or MySQL syntax to perform it.

Hopefully this will clear it all up:
Basically all i want is to use that <TR onClick....>
And in the href of that i need the code that will call the image URL that i inserted in the database for each item.

For ex: I have these fields in my DB table:
itemNumber ¦ Description ¦ UPC ¦ imageLarge
04-166 ¦ some item ¦ 0800880 ¦ http: //www.mywebsite.com/images/myfile.jpg

I need to find the correct way to do this (if possible):
<TR onclick="window.location.href='<?php imageLarge?>';">
The "imageLarge" is where i need some special php code that will call my DB,then Table,then FIELD.
The way my db is setup:
tnt_items(db) - air_fresheners(table) - imageLarge (field)

The TR link is not mandatory, if i can do this with just an href on a small icon, that will work too.

slimnutty5000

5:22 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



Nevermind, thanks for all the help anyways, but i figured it out myself.
It was the easiest of all and i feel stupid.
what i ended up using was this code for the link:
<a href="<?php echo $row_littletree['imageLarge'];?>" target="_blank">
And it worked perfectly.
Only one thing left i need, and its in another thread i just posted.
Please help me to figure this out:
[webmasterworld.com...]

Thanks