Jump to content


Photo

variable question


  • Please log in to reply
2 replies to this topic

#1 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 01:34 AM

I want have a variable called $id that includes the ID of my article. I have another variable called $article. What I want to know is how I would include the variable $id at the end of $article. For explain... if the ID equals 33 it would name the variable $article33. How do I use a variable within the name of another variable?

#2 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 01:49 AM

I think ${$id} is going to work fine.

#3 raila

raila
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 23 April 2006 - 07:21 PM

Im fairly new at this myselfe but try this lines:

IF YOU WHANT TO MAKE A LINK TO THE FILE:

echo"<a href='".trim($article)trim($id).".txt'>".trim($article)trim($id)."</a>";

if the file is in another directory(articles) use this:
echo"<a href='articles/".trim($article)trim($id).".txt'>".trim($article)trim($id)."</a>";

THIS INCLUEDS A WHOLE FILE:

include(trim($article)trim($id));
Or something like that should work fine.migt need some ""
somwhere in there, but im not sure.

if the name "article" is constant use:

//if $id = 33 like you wrote
include("article".trim($id).".txt"); this file is loaded : "article33.txt"



if the file is in another directory simply add the name of the directory :
include("articles/article".trim($id).".txt"); this file is loaded "articles/article33.txt"


Raila




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users