Jump to content


Photo

Placing variables in a link on the fly


  • Please log in to reply
4 replies to this topic

#1 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 July 2006 - 12:44 AM

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:

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;


I would like to pass the data from $story['description']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

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 14 July 2006 - 02:10 AM

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.co...rlencode($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.

#3 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 July 2006 - 03:33 AM

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 .

#4 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 July 2006 - 03:58 AM

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

#5 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 July 2006 - 04:30 AM

One more problem:
When I call the variable from the form page using:

<?
          urldecode($_GET['description']);
          echo $description;
?>

I get

{urlencode(my data here)}

What should I use to return just the data?

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users