Current location: Hot Scripts Forums » Programming Languages » PHP » a href and php variable problem


a href and php variable problem

Reply
  #1 (permalink)  
Old 01-05-08, 02:57 AM
dlmaster dlmaster is offline
New Member
 
Join Date: Jan 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy a href and php variable problem

Hi,

PHP Code:

<a href="home.php?user=<?php echo $id ?>&adr=<?php echo $adr[$j]?>"><?php echo $tt[$j?></a><br>
PHP Code:

echo "<a href='home.php?user=$id&adr=$adr[$j]'>$tt[$j]</a><br>"
I have tried both of this code to pass the value of adr to the page mentioned but the & symbol is not in the url... I still cannoot get the value of adr using $_GET.

In url box:

...home.php?user=abc&adr=def

but when mouse-over the link:

...home.php?user=abcadr=def


Is there anything wrong? I even try

<a href="home.php?user=<?php echo $id;?>&amp;adr=<?php echo $adr[$j];?>"><?php echo $tt[$j]; ?></a><br>

I test on IE7, the & is visible but in the end I still cannot get the value using $_GET.

Please advise.... Thank you.
Reply With Quote
  #2 (permalink)  
Old 01-05-08, 07:35 AM
var's Avatar
var var is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 51
Thanks: 0
Thanked 11 Times in 11 Posts
try this..

PHP Code:

echo "<a href='home.php?user=".$id."&adr=".$adr[$j]."'>".$tt[$j]."</a><br>"
Reply With Quote
  #3 (permalink)  
Old 01-05-08, 08:19 AM
dlmaster dlmaster is offline
New Member
 
Join Date: Jan 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Somehow I cannot display that link...

I've put <?php the echo code ?> but it is not displayed on the browser.
Reply With Quote
  #4 (permalink)  
Old 01-05-08, 11:43 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
You need to add semi colons on the end of each echo statement

PHP Code:

<a href="home.php?user=<?php echo $id?>&adr=<?php echo $adr[$j];?>"><?php echo $tt[$j]; ?></a><br>
or with the second one, you need to enclose the variables in braces like

PHP Code:

echo "<a href='home.php?user={$id}&adr={$adr[$j]}'>{$tt[$j]}</a><br>"
Did you not get any sort of error when you ran this script? Try putting
PHP Code:

error_reporting(E_ALL); 

at the top of your script when debugging, to turn on error reporting and view all errors generated by the script

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #5 (permalink)  
Old 01-05-08, 01:28 PM
dlmaster dlmaster is offline
New Member
 
Join Date: Jan 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Still the same... Error does not return any statement that relates to the missing &. Could it be the editor's browser problem?
Reply With Quote
  #6 (permalink)  
Old 01-09-08, 05:15 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:
Originally Posted by Jay6390 View Post
You need to add semi colons on the end of each echo statement
You can actually leave them out if you close the PHP tag right after.

And try using var_dump() to get information about the variables.

PHP Code:

var_dump($id);

var_dump($adr[$j]);
var_dump($tt[$j]); 
Reply With Quote
  #7 (permalink)  
Old 01-09-08, 05:18 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
ah, I thought that was only with short tags. still learning

also dlmaster, if you are still having trouble with this script, you may want to echo out the $id, $add, and $tt to see what values they contain, as it might be there that the problem actually lies...just realised, nico has mentioned that lol. oops
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName

Last edited by Jay6390; 01-09-08 at 05:20 AM. Reason: faux pas on my part...should read
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking to data from this php format? Columns Help? cyberfolli PHP 3 05-06-06 02:09 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Links from dir using php Bonzo PHP 5 03-22-04 07:46 PM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.