Jump to content

[SOLVED] question about making a table cell a link to a php script


Recommended Posts

Hello all, I have been trying to make a cell in an HTML table into a link.  Basically, I want to make it so that if I click on an album title, it will run a PHP script called processalbum.php with the album title as input.  I know I will have to use the GET method for this, but I'm not sure how to accomplish such a thing without a FORM.  But I don't need any input from the user, so I don't think I should need a FORM.  Here is the link (which doesn't quite work):

 

<td bgcolor = '#FFFFFF'><a href = 'processalbum.php?'.$album_name><font face = 'arial' size = '2'>$album_name</a></font></td>

Any ideas??  Thanks!

 

Brian

<?php
echo "<td bgcolor='#FFFFFF'><a href='processalbum.php?album_name=$album_name'><font face = 'arial' size = '2'>$album_name</a></font></td>";
?>

 

 

on the next page echo $_GET['album_name'] will show the album name

Correction...

<td bgcolor = '#FFFFFF'><a href = 'processalbum.php?album='.$album_name><font face = 'arial' size = '2'>$album_name</font></a></td>

 

You opened and closed the FONT and A tags in the wrong order...

I got it to work finally :)  and it was my fault about having </a></font> backwards in my original post.  Woohoo!  Now I think I am ready to begin populating my database.  Thanks for your help everyone!

 

Brian

You're welcome!

 

gevans - I believe your code is wrong because you're using single quotes - that would parse the $album_name as it is without adding the variable content into the equation.

 

He is using single quotes for the href etc, the main echo uses double quotes. It will parse it correctly.

Didn't notice that - my bad - half 3 in the morning here :(

 

I would have written this though...

<?php
echo '<td style="background-color: #FFFFFF"><a href="processalbum.php?album_name='.$album_name.'"><span style="font: 14px arial">'.$album_name.'</span></a></td>';
?>

Maybe a little overkill but I'm off to bed shortly...

If it was my code I would've done this;

 

<?php
echo "<td style=\"background-color: #FFFFFF\"><a href=\"processalbum.php?album_name=$album_name\"><span style=\"font: 14px arial\">$album_name</span></a></td>";
?>

 

But, each to their own!!

 

Yea, 3:30 tell me about it!! :)

I've always wondered why escape the slashes hiding the variables?

 

Can make debugging slightly more tricky when you're scrolling through lines of code and the variables are hidden. Don't know about you but my text editor colors everything differently so the variables stand out - I use Edit+

I've taken a look at that and nearly switched to it when I was making a website in Polish because Edit+ seemed to not want to encode the files properly - most of the Polish characters came out as something else!

When I was taking a look at Notepad++ the one thing that very nearly almost swayed me to buy it was the brace coloring for chunks of code like if() statements. Edit+ doesn't have it and it really looks handy!

 

http://notepad-plus.sourceforge.net/commun/screenshots/scrsh_braceIndentGuideHiLiting.gif

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.