tags:

views:

101

answers:

3

I want to be able to separate the birthday from the mysql data into day, year and month. Using the 3 textbox in html. How do I separate it? I'm trying to think of what can I do with the code below to show the result that I want:

Here's the html form with the php code:

$idnum = mysql_real_escape_string($_POST['idnum']);

mysql_select_db("school", $con);
  $result = mysql_query("SELECT * FROM student WHERE IDNO='$idnum'");

  $month = mysql_real_escape_string($_POST['mm']);
?>       
<?php while ( $row = mysql_fetch_array($result) ) { ?>
    <tr>
    <td width="30" height="35"><font size="2">Month:</td>
    <td width="30"><input name="mo" type="text" id="mo"  onkeypress="return handleEnter(this, event)" value="<?php  echo $month = explode("-",$row['BIRTHDAY']);?>">

As you can see the column is the mysql database is called BIRTHDAY. With this format:

YYYY-MM-DD

How do I do it. So that the data from the single column will be divided into three parts? Please help thanks,

+3  A: 

You can use list and explode to get desired result

 list($year,$month,$day)=explode("-", $row['birthday']);

hence $year contains year, $month contains month and $day contains Day, you can use it like this in your text boxes

<input name="mo" type="text" id="mo" value="<?php echo $month;?>">
<input name="dt" type="text" id="dt" value="<?php echo $day;?>">
<input name="yr" type="text" id="yr" value="<?php echo $year;?>">
nik
+1  A: 
$parts = expode('-', '1912-03-22'); // or split()
echo 'Year: ' + $parts[0] . '<br />';
echo 'Month: ' + $parts[1] . '<br />'; 
echo 'Day: ' + $parts[2] . '<br />';  
karim79
A: 

You could use php's explode function to split the date into its separate compoents:

$birthday ="1981-06-22";
list($year, $month, $day) = explode("-", $birthday);
echo "\nDay $day Month $month Year $year";
jkilbride