Solved

Weird anchor behaviors w/ PHP

Posted on 2004-08-24
22
307 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:worm22
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Works like a charm thanks a lot for going that extra step :)
0
 
LVL 11

Expert Comment

by:neester
Comment Utility
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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:worm22
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I've done that accidently before but I thought something an anchor wouldn't matter.
0
 
LVL 1

Expert Comment

by:worm22
Comment Utility
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
Comment Utility
Yeah - i think everyone has done it once before...
:)

cheers
0
 
LVL 1

Expert Comment

by:worm22
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now