PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 4th, 2002, 08:59 PM
Failte_PHP Failte_PHP is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Failte_PHP User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem reading Month from MySQL to PHP

What the heck am I doing wrong???

Simple situation, I use drop downs to populate dates on a form. I have a drop down for month, day and year. I store everything in the MySQL DB as yyyy-mm-dd, but on the web page I use Month day Year format. Now the user enters the date (simple enough) but then when they come back they can modify the date if they need to. To allow them to do this I first select their date information from the database...

START CODE SNIP:
php Code:
Original - php Code
  1.  
  2. $sql1Adate = "SELECT DATE_FORMAT(ecom1,'%m') as eddate1A FROM tbl_resume_edu where UID=$UID";
  3. $sql1Bdate = "SELECT DATE_FORMAT(ecom1,'%d') as eddate1B FROM tbl_resume_edu where UID=$UID";
  4. $sql1Cdate = "SELECT DATE_FORMAT(ecom1,'%Y') as eddate1C FROM tbl_resume_edu where UID=$UID";
  5. ....
  6. $result1Adate = mysql_query($sql1Adate);
  7. while($query_data1A = mysql_fetch_array($result1Adate))
  8. {
  9.  $eddate1A = $query_data1A[eddate1A];
  10. }
  11. $result1Bdate = mysql_query($sql1Bdate);
  12. while($query_data1B = mysql_fetch_arra($result1Bdate))
  13. {
  14. $eddate1B = $query_data1B[eddate1B];
  15. }
  16. $result1Cdate = mysql_query($sql1Cdate);
  17. while($query_data1C = mysql_fetch_array($result1Cdate))
  18. {
  19. $eddate1C = $query_data1C[eddate1C];
  20. }

END CODE SNIP:

Now with this information I populate the various drop down boxes. The year works fine so here is an example.

START CODE SNIP:
php Code:
Original - php Code
  1.  
  2. function ye()
  3. {
  4.     $ye[1] = "1960";
  5.     $ye[2] = "1961";
  6.     //You get the idea   
  7.     $ye[42] = "2001";
  8.         $ye[43] = "2002";
  9.         return $ye;
  10. }


php Code:
Original - php Code
  1.  
  2.     $etest13 = ye();
  3.      echo "<select name='ed_ye1'>";
  4.      echo "<option value='";
  5.      echo $eddate1C;
  6.      echo "'>";
  7.      echo $eddate1C;
  8.      echo "</option>";
  9.     for ($i=0; $i<44; $i++){
  10.      echo "<option value='";
  11.      echo $etest13[$i];
  12.      echo "'>";
  13.      echo $etest13[$i];
  14.      echo "</option>";
  15.     }
  16.     echo "</select>";

END CODE SNIP:

That works just fine, and so does the day of the month. Same idea as above. Trouble is with the month. Since I am storing the month in the 2 digit format in the database I have a little function to handle the DB to Human translation, or so I thought. Here is the funtion

START CODE SNIP:
php Code:
Original - php Code
  1.  
  2. function moTest()
  3. {
  4.     $moTest[01] = "January";
  5.     $moTest[02] = "February";
  6.     $moTest[03] = "March";
  7.     $moTest[04] = "April";
  8.     $moTest[05] = "May";
  9.     $moTest[06] = "June";
  10.     $moTest[07] = "July";
  11.     $moTest[08] = "August";
  12.     $moTest[09] = "September";
  13.     $moTest[10] = "October";
  14.     $moTest[11] = "November";
  15.     $moTest[12] = "December";
  16.     return $moTest;
  17. }

END CODE SNIP:


OK so when I call the variable that I have pulled from the DB as the month (for example 02 for February) I get nothing from the array. No error just a blank drop down. BUT if the variable is greater then 10 (or later in the year then October) IT WORKS!! Please see below...

START CODE SNIP:
php Code:
Original - php Code
  1.  
  2. <?php $mtest31 = moTest();
  3.      echo "<select name='mil_train_mo3'>";
  4.      echo "<option value='";
  5.      echo $eddate1A;
  6.      echo "'>";
  7.      echo $mtest31[$eddate1A]//Produces no output until $eddate1A  is greater then 10
  8.      echo $eddate1A;          //echo the correct value for the stored month
  9.      echo "</option>";
  10.     for ($i=0; $i<13; $i++){
  11.      echo "<option value='";
  12.      echo $i;
  13.      echo "'>";
  14.      echo $mtest31[$i];
  15.      echo "</option>";
  16.     }
  17.     echo "</select>";

END CODE SNIP:

Does any one see what I might be doing wrong? Or perhaps knows an alternative?

Reply With Quote
  #2  
Old November 4th, 2002, 10:36 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Problem reading Month from MySQL to PHP

The value coming from the database doesn't have the leading zero...so, it can't find a key in the array that is just 1 as the key is 01. Modify your function to not have leading zeros...

php Code:
Original - php Code
  1. function moTest()
  2. {
  3.     $moTest[1] = "January";
  4.     $moTest[2] = "February";
  5.     $moTest[3] = "March";
  6.     $moTest[4] = "April";
  7.     $moTest[5] = "May";
  8.     $moTest[6] = "June";
  9. //etc
  10.  

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Problem reading Month from MySQL to PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway