I came, I searched... No luck. (image map from database)
Moderator: General Moderators
I came, I searched... No luck. (image map from database)
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.
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.
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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
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
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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.
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
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.
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
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
I don't mind if the coordinates are seen just not the links that go with them.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.
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.
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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.
Just another idea...
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");
}
?>