Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include URL with parameter in table generated by php

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
0
0
NL
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 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.
 
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?

 
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.

 
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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top