Solved

Weird anchor behaviors w/ PHP

Posted on 2004-08-24
22
310 Views
Last Modified: 2012-08-13
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>
0
Comment
Question by:LiquidIce911
  • 10
  • 8
  • 4
22 Comments
 
LVL 1

Expert Comment

by:worm22
ID: 11886428
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
 
LVL 11

Expert Comment

by:neester
ID: 11887789
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
 
LVL 11

Expert Comment

by:neester
ID: 11887796
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:worm22
ID: 11887811
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
 
LVL 1

Expert Comment

by:worm22
ID: 11887834
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
 
LVL 1

Author Comment

by:LiquidIce911
ID: 11887837
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
 
LVL 1

Expert Comment

by:worm22
ID: 11887924
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
 
LVL 1

Accepted Solution

by:
worm22 earned 215 total points
ID: 11887945
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
 
LVL 11

Expert Comment

by:neester
ID: 11887963
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
 
LVL 1

Author Comment

by:LiquidIce911
ID: 11887966
Works like a charm thanks a lot for going that extra step :)
0
 
LVL 11

Expert Comment

by:neester
ID: 11887982
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
 
LVL 1

Expert Comment

by:worm22
ID: 11887986
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
 
LVL 1

Author Comment

by:LiquidIce911
ID: 11887996
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
 
LVL 1

Expert Comment

by:worm22
ID: 11887998
heh, yup yup.  love that black hole space.  it's given me more than a few gray hairs over the years. :)
0
 
LVL 11

Expert Comment

by:neester
ID: 11888046
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
 
LVL 1

Author Comment

by:LiquidIce911
ID: 11888090
I've done that accidently before but I thought something an anchor wouldn't matter.
0
 
LVL 1

Expert Comment

by:worm22
ID: 11888106
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
 
LVL 11

Expert Comment

by:neester
ID: 11888107
Yeah - i think everyone has done it once before...
:)

cheers
0
 
LVL 1

Expert Comment

by:worm22
ID: 11888114
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
 
LVL 11

Expert Comment

by:neester
ID: 11888166
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
 
LVL 1

Expert Comment

by:worm22
ID: 11888180
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
 
LVL 11

Expert Comment

by:neester
ID: 11888189
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question