Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Make dynamic PHP content a href...

maybe this is simple....not for me it seems



2:27 pm on Jun 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


I have created a table where the first row is the headings and the next is a repeat region that populatd until the end of the table. I would like to make one of the fields a clickable link when i will pass the ID to another page for updating.

I cannot for the life of me get it to work. I want to make the $ID a link. Any help apprecatied.

print "<tr>
"; etc etc


2:32 pm on Jun 11, 2002 (gmt 0)

10+ Year Member

Are you saying for like a sort by $ID type set up?

<a href="PHP_SELF?sort=$ID>$ID</a>

I am not sure if thats exactly what you are wanting or not though. What are you wanting the link to do exactly? Basically all you are going to have to do is put it in href and change it how you need it. If its going to a page called $ID.php just change it to be href="$ID.php" of course dont forget to pharse anything out that might need to be.


2:44 pm on Jun 11, 2002 (gmt 0)

10+ Year Member

This link looks like it should have some good reading for you ukgimp. Hopefully it can explain or show you a little better as to how to get the content to be dynamic the way you want it.


2:57 pm on Jun 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thanks for the links Knowles:

I just want to make one of the repeated sections a link. It falls down when i put a HREF tag in. I think it is something to do with mixing php and html and the fact that I dont really know when to use "s and 's and how many.

When I do this

<td><a href="#">$ID</a></td>

It does not like it. Where the link goes at this stage doesnt bother me to much it is just the fact that i cannot make a dynamic element linkable.



3:32 pm on Jun 11, 2002 (gmt 0)

10+ Year Member

You need to pharse out the "" in the anchor. So it would look like this
<td><a href=\"#\">$ID</a></td>
Since your print command is inside of double quotes. I do beleive you have to use double inorder to use the varible inside of it. Hopefully someone can give you a better explination as to how to and what to pharse. I just know you have to do it cause it stops running the php when it encounters them. Is it giving you an error when you add the anchor?


3:51 pm on Jun 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


That did the trick. Where have you been all day :-). I have been trying that for hours.

Do you know where I can learn that sort of thing. I have a php book but it does not seem to mention that.

Cheers Again


5:27 pm on Jun 11, 2002 (gmt 0)

10+ Year Member

It didnt mention anything about pharsing out \'s? Does it have a section about integration with HTML? Or anything like that? I would have to do some searchin I am sure there is info about it. I would say start at [php.net...] they will have something about it not sure how easy it will be to find though.


6:35 pm on Jun 14, 2002 (gmt 0)

10+ Year Member

It's called escaping. It's purpose is to differentiate a variable and text that is meant to be displayed or outputted to std output.


7:17 pm on Jun 14, 2002 (gmt 0)

10+ Year Member

Thank you ndjp! I knew pharsing was not the right word but it was the only one I could get to come out of my finger tips! Escaping the charater keeps it from being pharsed right? Pharsing is what happens when the code is executed right? Please tell me I am not living in a fantasy world!


7:57 pm on Jun 14, 2002 (gmt 0)

10+ Year Member

Hey Knowles... You are close! It's parsing actually. Code is parsed by, well, a parser such as a PHP, and by escaping the text you're essentially telling the parser to ignore that portion.


7:14 am on Jun 16, 2002 (gmt 0)

10+ Year Member

Parsing is a concept borrowed from grammar. When you parse a sentence, you actually sort out all the different bits and what they do so that you can understand the sentence.

For example, the first sentence in this post can be parsed like this:

Subject (noun phrase): "Parsing"
Predicator (verb phrase): "is"
Object (noun phrase): "a concept borrowed from grammar"

(Before any purists argue: Yes, in English grammar, the complement of "to be" is an object, so there.)

The object itself can be broken down into a noun phrase and an adjectival phrase.

You do this automatically in your brain, and this allows to work out the relationships between all the different words and so on.

Programming, scripting and markup languages have to be parsed in a similar way. The PHP parser breaks down a line of code into keywords, identifiers, values and so on.

Strings can be delimited by single or double quotes. But what happens if you want to include a quote inside your string? Take this line:

$quote="Hamlet said, "To be or not to be".";

The parser finds the identifier $quote, then the assignment operator = (which means "assign what's on the right of this operator to the identifier on the left"), then the double quote " which means, "From now until the next double quote is a literal string". It gets as far as:

"Hamlet said, "

...and that second double quote means, "The string ends here." Now the PHP parser is expecting something like a semicolon or a concatenation operator. Instead, it sees something it can't make sense of: what does To mean? It's not an operator, it's certainly not a semicolon, and it doesn't exist in PHP.

The backslash "escapes" the double quote: it means "Don't interpret the next character the way you normally do -- it's part of the string". So you have to write:

$quote="Hamlet said, \"To be or not to be\".";

When reading in values from form input fields, PHP automatically adds backslashes to escape all such characters -- just in case. But when you print them out on screen, because of the way it works, the backslashes actually get printed too. (This is because you're not printing a literal string, you're printing out the value of a variable.) To get around this, there is a function called stripslashes()

echo stripslashes($quote);

Use this when printing values taken from form input fields and databases, and the backslashes wil magically disappear.


7:07 am on Jun 17, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thanks rewboss.

Your post has really explained it to me. I have not come across a decent explanation of this before.

Have you thought of writing a book? ;-)



7:36 pm on Jun 17, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Pharsing is what happens when the code is executed right?

Pharsing, usually spelled "farcing" is when one posts something as a joke, as in a a farcical statement.

PHP is a non-recursive acronym for a Procrasting Hyperactive Pharser who should be doing real work.



8:05 pm on Jun 17, 2002 (gmt 0)

10+ Year Member

Really and all this time I thought it stood for Personal Home Page!


8:10 pm on Jun 17, 2002 (gmt 0)

10+ Year Member

Peepill Hoo Program


1:52 pm on Jun 18, 2002 (gmt 0)

10+ Year Member

Maybe its a loner program. People Hate People???

Featured Threads

Hot Threads This Week

Hot Threads This Month