Weird anchor behaviors w/ PHP

Hello.

I wrote my own forum script and I have a few problems. I want to do things like after a user posts it sends him to the thread and then use anchors to send them down to their post. I did all of that and it did not work for me. It doesn't work when I do it from a normal link or if I do it using header('Location :'....).

Is this a problem because I am also sending GET variables with it.. or maybe because I am using sessions ?

This is what a link I use looks like:
http://mysite.com/forums_threads.php?id=573&page=0#last

The last post anchor is written for the last post of the page as
<a name="last" id="last"></a>
LVL 1
LiquidIce911Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
worm22Connect With a Mentor Commented:
Note:  placed it beside user name because it was an easy string to search for. lol  as long as it's in the message and inside one of the table cells for the message it should work well enough.  Subject, Username, Date, MessageBody.  shouldn't matter too much except for personal taste and maybe how far into the messages it will scroll.
0
 
worm22Commented:
no and no.

this is a site I've used anchors, sessions, and GET variables and it works.  this is the URL generated by clicking on the link to the anchor (and I know there's too little info on the page to warrant anchors, not my idea lol).

http://www.nmusa-sdmp.com/site_publish/sub1.php?section=programs&sub=sponsors&h=0#participation

and this is the tag.

<a name="participation">


only differences I see with mine and yours are that I don't use ID or a close tag.  may be something funky to do with the close tag.  not sure why that would happen, but would be a quick shot to test it on your page.  If that's not it, then I have no idea, and I will be leaving to go out of town for a week or 2 tonight, so hope this helps, or someone else has a better idea of what's going wrong.

--
worm
0
 
neesterCommented:
Worm,

YOu should always include the closinng tag.
well in XHTML you must.

You DONT need the ID Value.
Only <a name=""></a>

You can also add the style:
style="display: none"

but IE wont work then, but mozilla will...
that could be an issue if you are hiding the anchor...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
neesterCommented:
But Yeah.
THE GET Variables are not a problem.

Check that you have havn't set the anchors to:

<a name="#post"></a>

the actual name shouldnt include the #...
I did this once, and I was stumped for a while!
It is easy to overlook...
0
 
worm22Commented:
well ok, it should be "<a name='some name' />" if you want to get technical.  but HTML does not require that.  An anchor tag with only a name is not a container tag.  Kinda like <br> (or <br /> if you're using XML or other strict markup languages).
0
 
worm22Commented:
acutually. you may be onto something with the ID.  seen some strange things happen when name and ID attributes are set to the same thing.
0
 
LiquidIce911Author Commented:
I had it without ID , doesn't work either. I do set some headers like don't cache the page, etc.. It's really weird for this to happen but it does on my forums.. It's for my community site at http://www.peoplegrade.com. You can sign up and check it out if you are really interested in helping, I will assign extra points.
0
 
worm22Commented:
ok, found the problem.  the anchor names are outside your tables cells.

---
<a name="last"></a>
      <a name="post7803"></a>
      <tr bordercolor="#000000" bgcolor="#397BB3">
        <td width="23%" align="left" valign="middle" nowrap background="images/forumtop.gif" bgcolor="#397BB3" class="boxtop"><div align="center" class="bodytext"></div>
          <div align="left" class="boxinfo">
            <div align="center"><strong><span class="boxinfo3">Aug 24, 2004 7:16pm</span></strong></div>

          </div></td>
        <td height="16" align="left" valign="top" nowrap bordercolor="#000000" background="images/forumtop.gif" bgcolor="#397BB3" class="boxtop"><div align="center" class="bodytext">
          <div align="left"><strong>test post (delete me after 7:30pm EST)</strong></div>
        </div>                   </td>
        </tr>
-----

try changing it to:

-----
     <tr bordercolor="#000000" bgcolor="#397BB3">
        <td width="23%" align="left" valign="middle" nowrap background="images/forumtop.gif" bgcolor="#397BB3" class="boxtop"><div align="center" class="bodytext"></div>
          <div align="left" class="boxinfo">
            <div align="center"><strong><span class="boxinfo3">Aug 24, 2004 7:16pm</span></strong></div>

          </div></td>
        <td height="16" align="left" valign="top" nowrap bordercolor="#000000" background="images/forumtop.gif" bgcolor="#397BB3" class="boxtop"><div align="center" class="bodytext">
          <div align="left"><strong>test post (delete me after 7:30pm EST)</strong></div>
        </div>                   </td>
        </tr>
      <tr bordercolor="#D9E2E9" bgcolor="#397BB3">
        <td  width="23%" height="20" valign="top" nowrap bordercolor="#D9E2E9" bgcolor="#397BB3"><div align="center"><a name="last"></a><a name="post7803"></a>
          <p><strong><a href="view.php?username=worm22" class="boxtop">worm22<br>

                <br></a></strong>
------

saved the source of the page and tested it.  as it was gave me the same problem (scrolls half-way down the page), but once placed inside the table cells it worked fine.

--
worm
0
 
neesterCommented:
I have done some testing.

this was with IE...

It should work with/without ID...
it should work with/without </a> or /> (doesnt need closing)

so correct code or not, it should still work.

i tested using the name "last" etc..
i registered at your site.
brb which i login and check the code :)
0
 
LiquidIce911Author Commented:
Works like a charm thanks a lot for going that extra step :)
0
 
neesterCommented:
Ahhh yes.
As worm said.
that would cause a problem.

The information inbetween table code...
ie.
after the
<table> tag
and anything not inside hte <td> or <tr> tags is mysterious.

it seems to be hidden from the users view, kind of a peek-a-boo bug in IE...
it is odd - and that would be the problem for sure!

according to the HTML rendering, the Anchor doesnt have a location set....
while the renderer will jump to the HTML anchor, there is no location rendered for that spot since its in the black hole of the table...
0
 
worm22Commented:
no problem.  been there done that a few times, but I've been at it so long I can't remember half my mistakes til I see them in the code itself. :)

--
worm
0
 
LiquidIce911Author Commented:
yeah it was weird I never knew that would happen. I am not a big fan of HTML since it is very weird with small things like this. But feel free to stick around my site and give some feedback if you are interested in that sort of stuff. I did the scripting from scratch.
0
 
worm22Commented:
heh, yup yup.  love that black hole space.  it's given me more than a few gray hairs over the years. :)
0
 
neesterCommented:
Worm22,
It actually is weirder....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
      <title>New document</title>
<meta name="generator" content="TSW WebCoder">
</head>


<body>


<table>
<tr>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
</tr>
<tr>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
</tr>
A LOT OF DATA HERE...
Just gets placed at the top of the table...
above the &lt;table> tag... weird aint it!
So this will appear above the table itself, below...
although this is indeed, in the center of the content...

some browsers will display this...
some wont...
<tr>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
</tr>
<tr>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
      <td>HEY</td>
</tr>
</table>


</body>
</html>
0
 
LiquidIce911Author Commented:
I've done that accidently before but I thought something an anchor wouldn't matter.
0
 
worm22Commented:
lol, I've done that.  left me trying for days to figgure out what was wrong the first time I did it.  Turned out the IF statement which genereated the opening tags for the table cells was bass ackwards. lol

--
worm
0
 
neesterCommented:
Yeah - i think everyone has done it once before...
:)

cheers
0
 
worm22Commented:
so here's a question:

why does a non-contatiner tag get rendered 1/2 way down the table, while text gets redered above it?

--
worm
0
 
neesterCommented:
If i knew what you were asking...
I wouldnt be able to answer it anyway.
the tables have very undesirable effects when not implemented properly...

thats why i only use them for tabulated data...
0
 
worm22Commented:
ah,  I use them frequently and more often than not heavily nested. lol  Gives ya a headache sometimes but looks nice when you finally get it right.

--
worm
0
 
neesterCommented:
I use CSS for all my design and thats why i stay away really...


anyway.
:)
this job is closed now :)
hehehe

cheers - table chat - how lame are we :D
hehehe
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.