Jump to content

Archived

This topic is now archived and is closed to further replies.

waverider

Placing variables in a link on the fly

Recommended Posts

Hello,
I have a web page which draws product data from MySql and prints each product's information from an array in seperate tables created on the fly. Each iteration produces a new table with different product data. Each table has a link to a generic form which is activated through javascript in the link.  Code for display of each table as below:
[quote]echo <<<BLOCK
  </td>
          <td width="20%" height="20" align="left" valign="top" bgcolor="#444444"><div align="left"><strong><font color="#999900" size="2" face="Arial, Helvetica, sans-serif">{$story['make']}</font></strong></div></td>
          <td width="43%" height="20" align="left" valign="top" bgcolor="#444444"><strong><font color="#99CC00" size="2" face="Arial, Helvetica, sans-serif">{$story['model']}</font></strong></td>
          <td width="20%" height="20" align="left" valign="top" bgcolor="#444444"><strong><font color="#99ff00" size="3" face="Arial, Helvetica, sans-serif">{$story['price']}</font></strong></td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#444444"><font face="Arial, Helvetica, sans-serif">{$story['description']}</font></td>
  <td width="20%" align="center" bgcolor="#444444"><strong><font color="#ffcc00" size="5" face="Arial, Helvetica, sans-serif"> ?<br /> <strong><font color="#999900" size="1" face="Arial, Helvetica, sans-serif"><a href="javascript: newWindow('http://www.mysite.com/contact.php')">CLICK HERE</font></strong></td>
      </tr>

</table>
BLOCK;[/quote]

I would like to pass the data from [color=green]$story['description'][/color]through the URL to the form and print it on the form.  How can I do this so that on each iteration stores the correct value of the variable for that particular product in the URL?

Thanks

Share this post


Link to post
Share on other sites
You really should use css and class declarations for all of your formatting rather than repeating the same stuff over and over...it makes it difficult to read.

Anyway, what you want to do is:

<a href="javascript: newWindow('http://www.mysite.com/contact.php?description={urlencode($story['description'])}')">

Then on your contact.php page, use:

echo urldecode($_GET['description']);

Remember that there is a limit to how much data can be passed in the url, so if the descriptions are long, you may not be able to do this.

Share this post


Link to post
Share on other sites
Thanks hitman6003,
As soon as I put the code ?description={urlencode($story['description'])} into the link all I get is a blank page - remove the code again and things are back to normal ?  I have checked that there are no extra spaces etc I have also tried with a number of small variables to remove size as an issue.

And - yes- I must replace all that with css - next job .

Share this post


Link to post
Share on other sites
It looks like I may have solved this.  It appears that urlencode() doesn't like the form $story['description'] so I have placed the data in a standard variable and called this with ?description={urlencode($description)} which works great - thanks for the assistance

Share this post


Link to post
Share on other sites
One more problem:
When I call the variable from the form page using:
[quote]<?
          urldecode($_GET['description']);
          echo $description;
?>[/quote]
I get [quote]{urlencode(my data here)}[/quote]
What should I use to return just the data?

Thanks

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.