/    Sign up×
Community /Pin to ProfileBookmark

Trouble getting anchor to work in PHP code

This question refers to this sample page on my test site:

[URL=”http://www.twdesign.ca/up/display_tattoos_2009.php”]http://www.twdesign.ca/up/display_tattoos_2009.php[/URL]

The following section of PHP code:

<table cellspacing=”0″ cellpadding=”0″ border=”0″ align=”right”>
<?php
while($row = mysql_fetch_row($result2))
{
$active = $row[0];
$imagenum = $row[1];
echo “<tr><td><a name=’placeholder$imagenum’ href=’display_tattoos_2009.php?in=$imagenum’ onClick=’swap(‘toppic’,’$imagenum’)’><img class=’opacity’ name=’$imagenum’ id=’$imagenum’ src=’tattoothumbnails/$imagenum.png’ width=’72’ height=’72’ alt=’$imagenum’></a></td></tr>n”;
}
?>
</table>

does what I want I want it to do on the page, displays a CSS controlled table on the side of the site to allow viewers to click on tattoo images and get a larger view, plus several other photos of the same tatoo from different angles.

What I’m having trouble with is that when the page reloads, the scrollbar automatically goes back to the top of the table and you have to scroll all the way down again to see the next tattoo.

I tried [B]changing the href[/B] to ‘display_tattoos_2009.php?in=$imagenum#placeholder$imagenum’ and to ‘display_tattoos_2009.php#placeholder$imagenum?in=$imagenum’, neither of which worked.

I tried using an [B]onLoad [/B]in the BODY such as:
<script type=”text/javascript”>
function goToAnchor() {
location.href = “display_tattoos_2009.php?in=$imagenum#placeholder$imagenum”;
}
</script>

using PHP to write the javascript and pass the variable, but again no luck.

I tried ouptutting the table as a form and using [B]FOCUS()[/B], still no joy.

Maybe it’s the lack of sleep, maybe it’s that I’ve been looking at this code different ways for nigh on 24 hours now (interspersed with other projects to get my mind away form actively working on it), but I am at an impass.

Any help?

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@HydroSep 27.2010 — The php part of your javascript isn't in the php tags. Not sure if its possible to call php inside of javascript as I'm still learning. Hopefully thats given you somewhere to go with your javascript idea anyway!
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — I just didn't put the php code in I want pepople to be able to see the final output of the php code instead.
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — Bleah, let's try that again.....

I just didn't put the php code in, I wanted people to be able to see the final output of the php code instead.

I really do need to sleep!
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — <script type="text/javascript">

<?php

echo('<body>');

echo ('function goToAnchor() {');

echo ('location.href = "display_tattoos_2009.php?in=');

echo ($imagenum);

echo ('#placeholder');

echo ($imagenum');

echo ('";');

echo ('}');

?>

</script>
Copy linkTweet thisAlerts:
@ChipzzzSep 27.2010 — You'll probably have to change your image with an AJAX call rather than updating the whole page. This approach would have other advantages as well. Nice tats, by the way.
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — I suppose if I had to, I could go back and use iframes to hold the different areas of content, but for some reason (which eludes me right now) we didn't want to use iframes in this iteration of the site.

If the scrolled material were in one iframe and the photos in another, I wouldn't have to worry about reloading the scrolled material each time.
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — AJAX is a bit beyond me at this point. I'm great with html/php/css, as well as photoshop, but javascript and AJAX elude me. Would you have an example I could look at?

Not my tattoo work, but I've been doing their website since 1995. Daemon does do good work.
Copy linkTweet thisAlerts:
@ChipzzzSep 27.2010 — This may be a good opportunity to enhance your javascript skills. This will help: http://www.w3schools.com/ajax/ajax_intro.asp but try to get that sleep first... it's not a 10 minute project ?
Copy linkTweet thisAlerts:
@NBLWebmasterauthorSep 27.2010 — Picture me whacking my head against my desk. I get so focused on doing things one way that sometimes I forget there are usually 15 other ways to do it.

First thing in the morning I'll go through W3Schools (where I have spent many a fine hour reviewing and updating my skills) and I'll probably have it working on the live version of the site http://www.urbanprimitive.com by noon.

Many Thamks!
×

Success!

Help @NBLWebmaster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...