×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Include URL with parameter in table generated by php

Include URL with parameter in table generated by php

Include URL with parameter in table generated by php

(OP)
From a ODBC database I generate a table containing two columns: a date and a text that may contain a link to another php page (see for example last row in https://www.pdavis.nl/ShowShip.php?id=50). As long as this link does not contain a parameter in the URL this works fine:

CODE

<tr><td class=pright><a id="d186508150"></a>Tu&nbsp;15&nbsp;August&nbsp;1865</td><td colspan=3><a href='Cherbourg.php'>Cherbourg visit</a></td></tr> 

however I want to contain a parameter in the URL of the link (this is the same parameter that is contained in the URL of the calling page (in other words, the page Calling.php?id=50 will contain a link to Called.php?id=50)

I therefore (as a first step with a hard-coded parameter) replaced the simple

CODE

<a href='Cherbourg.php'>Cherbourg visit</a> 

by

CODE

<a href='Cherbourg.php'>Cherbourg visit</a>
<?php
echo '?id=50\n';
?> 

But this doesn't work; the added script is just included in the generated script:

CODE

<tr><td class=pright><a id="d186508150"></a>Tu&nbsp;15&nbsp;August&nbsp;1865</td><td colspan=3><a href='Cherbourg.php'>Cherbourg visit</a>
<?php
echo '?id=50';
?></td></tr> 

Any suggestions welcome.

RE: Include URL with parameter in table generated by php

If you want the parameter passed in the URL, why are you passing the parameter long after you've closed the "a href" attribute? This issue is more of a question of HTML than PHP.

The other links on that page suggest effective implementation of parameters being passed in the URL. Can you use those as a guide?

RE: Include URL with parameter in table generated by php

(OP)
Yes indeed; slip of the brain there, but

CODE

<a href='Cherbourg.php
<?php
echo '?id=50';
?>
>Cherbourg visit</a> 

doesn't fare any better:

CODE

<tr><td class=pright><a id="d186508150"></a>Tu&nbsp;15&nbsp;August&nbsp;1865</td><td colspan=3><a href='Cherbourg.php
<?php
echo '?id=50';
?>
>Cherbourg visit</a></td></tr> 

I have a feeling the problem is related to the fact that I am only submitting the script after the php interpreter has done its thing, so that it isn't recognised as php. However I don't want to organise this in the script of the calling page, as it only concerns one row in a database of thousands of records.

This 'Cherbourg visit' page must be called from 20 pages with different id values (out of a total of 1700). I could just add 20 rows to the database with

CODE

<a href='Cherbourg.php?id=nn'>Cherbourg visit</a> 

as appropriate, but that would be very inellegant.

RE: Include URL with parameter in table generated by php

(OP)
The solution lies with Javascript and not with php:

First define a Javascript variable with php in the calling programme (minimal overhead)

CODE

echo "<script>\n";
echo "var myID = " . $id . ";\n";
echo "</script>\n"; 

then put the following in the text field of the database

CODE

<span id='link'>this gets replaced</span>
<script>
document.getElementById('link').innerHTML='<a href="Cherbourg.php?id='.concat(myID,'">Cherbourg visit</a>')
</script> 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close