How to use variables names in other variables ?

I am trying to retrieve some fields from database within phpnuke (PHP / MySQL CMS)
the field in question is the user_regdate (The date the user registered on the site)
The format of the field is MMM DD, YYYY i.e. Jan 10, 2006

I wanted to pull the results from the database and populate a table with how many members joined that month

Code i have so far is:-

            echo "<table>";
            echo "<tr><td>Year</td><td>Month</td><td>Users</td></tr>";
            $querystring = "SELECT user_regdate FROM nuke_users";
            $query = $db->sql_query( "$querystring" );
            while (list($regdate) = $db->sql_fetchrow($query)) {
                  list($monthday,$year) = explode(",",$regdate);
                  list($month, $day) = explode(" ", $monthday);
                  $year = trim($year);
//                  echo "Month - $month<br>Year - $year<br><br>";
                  if ($month=="Jan" && $year=="2006") {
                        echo "match<br>";
                        $month.$year++;
                  }
            }
      echo "Jan 2006 - " . ${Jan2006} . ":<br>";
      }

This does pull the info out and split it into variables i.e. $day, $month and $year but i am then simply trying to get it to create matching set variables that accummulate up i.e. Jan2006, Feb2006, Mar2006 etc and then adding 1 to each variable if it matches to get total amount per month

The problem is that the adding up code "$month.$year++; doesnt seem to work, i have also tried $$month$year++;

I know i have used this before somehow but too long ago to remember and cant find the code snippet now !!
davidburleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
You can have
$year++;
$date = $month.$year;

-r-
0
davidburleyAuthor Commented:
ah y but that doesnt populate my variables properly i.e. i want a seperate variable for every month of the year for every year
i.e. $Jan2005, $Feb2005, $Mar2005, $Apr2005 etc and each month would simply hold the count of how many users joined during that month.
0
BogoJokerCommented:
$arrayMonths = array('Jan2005' => 0, 'Feb2005' => 0, 'Mar2005' => 0, 'Apr2005 => 0,....)

Now when you say: $Jan2005 you could just do:
$arrayMonths['Jan2005']

To Increment them:
$arrayMonths['Jan2005']++;

That sound ok for you?
Joe P
0
BogoJokerCommented:
I initailize the array with a single line syntax:
$array = array('a' => 0)

That is the same as:
$array = array();
$array['a'] = 0;

I am not familier with 2d arrays in php but I am sure experts like Roonaan know how.  They could potentially improve my code so that you have a seperate section for each month, like this:
$arrayMonths['Jan']['2005'] = 0;
Which would be different from $arrayMonths['Jan']['2006'];

But I don't know how to do that yet, It will probably not be too difficult if you are intrested in such an improvement.
Joe P

Note: You can also use this with the code I gave you:
$registerTime = 'Jan2005';
echo $arrayMonths[$registerTime]; // this will print out the current number in $arrayMonths['Jan2005'] so it is variable safe inside those []s
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
x95guzikCommented:
Below is a simplified example with the method you are looking for I believe.

//put the 'm' in front for PHP will not accept a number for its variable first character
$month = "m12";
$year = "2005";

$monthYear = $month.$year;
${$monthYear} = 16;

$month = "m01";
$year = "2006";

$monthYear = $month.$year;
${$monthYear} = 12;

echo $m122005;
echo "<BR>".$m012006;

${$monthYear}++;

echo "<br>".$m012006;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.