homepage Welcome to WebmasterWorld Guest from 54.167.238.60
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Make dynamic PHP content a href...
maybe this is simple....not for me it seems
ukgimp




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

Hello

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>
<td>$ID</td>
<td>$PR</td>
<td>$UU</td>
<td>$PW</td>
<td>$NA</td>
<td>$EM</td>
<td>$PH</td>
</tr>
"; etc etc

 

Knowles




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

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.

Knowles




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

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.
[webreference.com...]

ukgimp




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

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.

Cheers

Knowles




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

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?

ukgimp




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

Cheers

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

Knowles




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

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.

ndjp




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

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.

Knowles




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

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!

ndjp




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

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.

rewboss




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

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.

ukgimp




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

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? ;-)

Cheers

ergophobe




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


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.

Tom

Knowles




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

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

toadhall




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

Peepill Hoo Program

Knowles




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved