Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

get link filename another file.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

get link filename another file.

Postby faces » Thu Apr 18, 2013 11:39 am

File1:
<?php 
$home['1']='home/1.php'
$home['2']='home/2.php'
?>
File2:
<?php
Include File1.php
<a href="<?php echo $home['1']; ?>">home 1</a>
?>


Whats wrong is that simple script?
Can someone help me little bit  ?
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm

Re: get link filename another file.

Postby seandisanti » Thu Apr 18, 2013 11:54 am

you've actually got a pretty good number of errors crammed into that tiny little script. from top here we go:

1) you're not ending your statements in the php sections with semicolons
2) you've capitalized 'Include' and have not quoted the filename to be included
3) you are writing markup without echoing it out '<a href=...'
4 & 5) you open a new php block inside of a php block, and you are using echo to try to concatenate strings within a statement
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: get link filename another file.

Postby faces » Thu Apr 18, 2013 12:08 pm

File1:
<?php 
$home['1']='home/1.php';
$home['2']='home/2.php';
?>

File2:
<?php
include "File1.php"
<a href="$home['1'];">home 1</a>
?>

Is that right?
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm

Re: get link filename another file.

Postby seandisanti » Thu Apr 18, 2013 12:16 pm

You've rectified #1 in the first section, #2 is good (though the line needs to end with a semicolon) #3 is not addressed, and #5 is improperly addressed. concatenation in php is done using a period.

You should also be aware that you're not outputting anything from either code block, and even once you address #3, your output will be...
File1:File2Home 1

and Home 1 will be a link
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: get link filename another file.

Postby faces » Mon Apr 22, 2013 6:03 am

Thanks i get it work:)
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron