Greetings,

I am fairly new to php but I have been studying it intently.

My question has to do with pulling a global variable from the URL, and assigning that variable into the call-up for an array. Let me explain further...

I am setting up a collectors site for trading cards for a family member, and I want to call up a single php page and define a card number in the URL, like this...


http://somewebsite.com/detail.php?card=0001

Then I want to read in that card=0001, and assign it's value to an array call-up, that will fetch the array associated with that card.

I am using a standard variables.php file, and simply importing it into the Detail.php page. I have got the variables to import, but so far I have had to specifically define the variable I am calling up. As such,


<?$CARD0001["title"];?>

However doing it this way means that for the thousands of cards featured, there will need to be a seperate page for each. YUK! My goal is to actively change the number in "Card0001", based upon the URL. And simply have one page that adjusts the inputs based on the URL.

Now I've tried the following method, but so far I just can't make it work,


<?php
include("template.html");
include("variables.php");

if (!isset($_GET['card'])) {
  $page = "card";
} 
else {
  $page = $_GET['card'];
}
?>

This code does what I want. It does get the value of "card" from the URL, because a simple print statement verifies it.

However after trying many ways to input the value of "card" into the array query I have been unable to associate the two. This was one way I have attemped to do it:


<?$CARD"$page"["title"];?>

But of course this doesn't work...

Now, can this be done, or does anyone have any recommendations on how I can pass the value of the "card" from the URL, into the array call-up here?

Any help would be greatly appreciated. Thanks.

WebG0PHER

    Well, I think the easiest way would be to just use a MYSQL Database.. When ?id=1 is inputed into the browser it looks up the query with the id 1 and takes out the other information.. If you want help setting up all of that PM me.

      Yeah I figured that I should have used an SQL database instead. I was being lazy and was attempting to create a quasi-database using php and tons of array's. I decided to just do it right, and set up the database and it's working perfectly now. Thanks.

      WebG0PHER

        Write a Reply...