I came, I searched... No luck. (image map from database)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

I came, I searched... No luck. (image map from database)

Post by Drachewyn »

Okay I searched around and didn't find the answers I sought.

What I want to do is have an ISMAP on my webpage but one that
takes the links from a database when clicked.

I have one now that works with a mymap.map file but I don't like
this because anyone can view this file.

I want the same functionality as the ISMAP, i.e. all coordinates available
with one default specified but using a database to store the links and
pulling the links from there when the image is clicked.

I am still working to learn PHP but none of the books I have
really helped me to figure out this dilemma.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

Post by Drachewyn »

Yeah I found that link in my search but that really doesn't explain how to use a mysql database to store the link information. Thanks though. :)
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Assuming that you are only using rectangular areas for your image map, you could have a database table as below:

ImageMapTable (
Link VARCHAR(255)
XStart INT(4) UNSIGNED
XEnd INT(4) UNSIGNED
YStart INT(4) UNSIGNED
YEnd INT(4) UNSIGNED
)

Then, once you have the co-ordinates of the click, use a query like:

SELECT Link FROM ImageMapTable WHERE $X <= XStart AND $X >= XEnd AND $Y >= YStart AND $Y <= YEnd
User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

Post by Drachewyn »

That seems exactly like what I was looking for. Thanks :)

Would that also work for a default link so that when unspecified coordinates are clicked it goes somewhere?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Well, in successful cases, your query will return 1 record.

Using php you can use the mysql_num_rows() function to see how many records were returned.

If 0, then go to your default link.

The problem you might face is finding the co-ordinates of the click. I dunno how you're going to do that.
User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

Post by Drachewyn »

Not sure what you mean by finding...

I already know which coordinates I want to use if that is what you meant.

If not then what did you mean by finding?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Well, this is the thing. PHP gets interpretted before the HTML is downloaded by the user.

So that means that all database interaction is done before the user even sees the image map.

This allows you to easily retrieve data from the database and show it to the user. So, you could always query the database for the image map information then write the image map data to the HTML file, but that would be similar to having your .map file. The user could view source and see the links and co-ordinates, etc.

From your first post, it sounded like you didn't want the user be able to access this sort of thing.

If that's the case, then you CAN'T use an image map, cause the co-ordinates must be contained either within the HTML file itself, or in your.map file.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

If you want to query the database after the user clicks, then you can rig up a method thats SIMILAR to an image map.

But, because it's NOT an image map, you have to somehow find the co-ordinates of the user's click yourself, instead of relying on the browser to figure that out for you.

This could probably be done in JavaScript, but I wouldn't know the code to do it.

Then, once you have the co-ordinates, you could then redirect the user to a .php file with a url construct like this:

action.php?x=80&y=80

This tells action.php that the user clicked at (80, 80) and then you can use php to query the database and find out the appropriate link to go to, then you can use php again to redirect the user to that link.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Hmm... maybe this ISMAP thing CAN give you the co-ordinates properly.

If so, just ignore anything up there that doesn't make sense. : )
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

I believe if it's a form with an image as the submit button the x and y coords will be sent to the script.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

hedge wrote:I believe if it's a form with an image as the submit button the x and y coords will be sent to the script.
Yeah! That's a good idea!
User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

Post by Drachewyn »

microthick wrote: If that's the case, then you CAN'T use an image map, cause the co-ordinates must be contained either within the HTML file itself, or in your.map file.
I don't mind if the coordinates are seen just not the links that go with them.

Currently the .map file with all the links I am using is viewable and try as I did I could not make it not viewable and still have the image map
work as it should.

This will take some thinking and work but I think I can do it. I just hope I can do it before the Jan 2 deadline I set for myself. :D
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

If that's the case, you could also do this:

Do your image map as however you want it done.

But make all links of the format:
somefile.php?link=a
somefile.php?link=b
somefile.php?link=b

Then, in somefile.php you can see what the value of link is, and redirect accordingly.

Code: Select all

<?php

if ($_GET["link"] == "a") {
     header("Location: asecretlocation.htm");
} else if ($_GET["link"] == "b") {
     header("Location: bsecretlocation.htm");
}
?>
Just another idea...
User avatar
Drachewyn
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 3:55 am

Post by Drachewyn »

Thanks I will explore that route and see how it goes.
This will be my first real PHP script I just hope
I don't screw it up. :D
Post Reply