0

This is confusing. I'm creating an index for a MySql table of structure "yyyymm", where "yyyy" is year (e.g. 2011) and "mm" is month (e.g. 02). I acquire them with:

$yyyy = date('Y', time());
$mm = date('m', time());

I subsequently convert them to strings with strval and concatenate them (I've also used the other code below the strval example:

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";

I then insert $edition into a MySql table as an index of char(6) but the result is always reversed. Instead of $edition being yyyymm (e.g. 201102), it ends up being mmyyyy (e.g. 22011). I can't seem to zero pad the mm either.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by wfray
0
$yyyy = date('Y', time());
$mm = date('m', time());

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";
echo $edition;

Gives me 201102

Show your SQL query and MySQL table schema

0
$yyyy = date('Y', time());
$mm = date('m', time());

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";
echo $edition;

Gives me 201102

Show your SQL query and MySQL table schema

It's resolved - I did all the above (typical debug stuff) previously and got the same result so I was very confused. Your reply got me thinking that there must be some code being executed that was not obvious. It turns out I had two versions of this code; the base code and the developmental code. Within both versions I was re-entering the code when a particular button was being clicked. Stupidly, in the developmental version, I never changed the name of the module to re-enter on submit. So, I started with the developmental code and re-enterd the base code, which caused the error. Lesson learned. THANKS for helping to get my brain in gear.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.