SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date function from array

    Hi guys:
    i need some help on date function...

    Let me explain.
    i have a form where i use for loop to increment the date depend on the $_GET .
    PHP Code:
    <?php
                        
    for($i=1;$i <= decrypt_str($_GET['cusers']);$i++){

                        echo
    '<select class="textbox2" name="dobdd[]">';
                        echo
    '<option value="1">1</option>';
    PHP Code:
    <?php

                        
    for($i=1;$i <= decrypt_str($_GET['cusers']);$i++){
                        echo
    '<select class="textbox2" name="dobmm[]">';
                        echo
    '<option value="1">1</option>';
    PHP Code:
    <?php
                        
    for($i=1;$i <= decrypt_str($_GET['cusers']);$i++){
                        echo
    '<select class="textbox2" name="dobyyyy[]">';
                        echo
    '<option value="1980">1980</option>';
    I split the date into 3 parts like day,month,year.

    Then use this php main script to combine
    PHP Code:
    $dobdd=($_POST['dobdd']);
         
    $dobmm=($_POST['dobmm']);
         
    $dobyyyy=($_POST['dobyyyy']);
    $dtdob[] =$dobyyyy."-".$dobmm."-".$dobdd
    The date is coming from array so in the $_GET there are 2 child.
    Then it will saved to db like this:
    PHP Code:
    $sql .= "`dtdob` = ('" $dtdob[0] . "'), "
    $sql .= "`dtdob` = ('" $dtdob[1] . "'), "
    The problem is that how to split the date for two or three child to enter it
    to the db seperatly for every child...
    Any help will appreciated.
    Thanks

  2. #2
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any idea guys.

  3. #3
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any idea guys...
    I am struggling with it.

  4. #4
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *EDIT*

    Okay, sorry, I misread.

    do this..

    PHP Code:
    $dtdob = array();
    for (
    $i 0$i <= count($_POST['dobyyyy']); $i++) {
        
    $dtdob[$i] = $_POST['dobyyyy'][$i]."-".$_POST['dobmm'][$i]."-".$_POST['dobdd'][$i];

    that should populate the $dtdob array with the form values.
    - the lid is off the maple syrup again!

  5. #5
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by notepad_coder View Post
    *EDIT*

    Okay, sorry, I misread.

    do this..

    PHP Code:
    $dtdob = array();
    for (
    $i 0$i <= count($_POST['dobyyyy']); $i++) {
        
    $dtdob[$i] = $_POST['dobyyyy'][$i]."-".$_POST['dobmm'][$i]."-".$_POST['dobdd'][$i];

    that should populate the $dtdob array with the form values.
    Thanks for ur help and time.
    This is one coming from array:
    PHP Code:
    ($_POST['dobyyyy']); 
    But here u mention this:
    PHP Code:
    $_POST['dobyyyy'][[/B]$i]."-"
    Can u explain what is the logic behind it.

  6. #6
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Say there are two items in the $_POST['dobyyyy'] array... this is what my code will do..

    PHP Code:
    $dtdob['0'] = $_POST['dobyyyy']['0']. "-" .$_POST['dobmm']['0']. "-" .$_POST['dobdd']['0'];
    $dtdob['1'] = $_POST['dobyyyy']['1']. "-" .$_POST['dobmm']['1']. "-" .$_POST['dobdd']['1']; 

    Here's an example of a script I have doing the same thing, almost.
    PHP Code:
    <?php
    function hanks($c) {
        for (
    $i 0$i strlen($c); $i++) {
            if (
    $c[$i] == "h") { $c[$i] = 1; }
            if (
    $c[$i] == "a") { $c[$i] = 2; }
            if (
    $c[$i] == "n") { $c[$i] = 3; }
            if (
    $c[$i] == "k") { $c[$i] = 4; }
            if (
    $c[$i] == "s") { $c[$i] = 5; }
            if (
    $c[$i] == "p") { $c[$i] = 6; }
            if (
    $c[$i] == "r") { $c[$i] = 7; }
            if (
    $c[$i] == "i") { $c[$i] = 8; }
            if (
    $c[$i] == "c") { $c[$i] = 9; }
            if (
    $c[$i] == "e") { $c[$i] = 0; }
            if (
    $c[$i] == "x") { $c[$i] = $c[($i-1)]; }
        }
        return 
    $c;
    }

    for (
    $i 0$i $_POST['rows']; $i++) {
        
    $qty $_POST['qtys'][$i];
        
    $ven $_POST['vendor'][$i];
        
    $pid $_POST['pid'][$i];
        
    $des $_POST['desc'][$i];
        
    $cos $_POST['cost'][$i];
        if (
    $ven == "United") {
            
    $cos hanks($cos);
        }
        
    $pri $_POST['price'][$i];
        
        
    $cos sprintf("%1.2f", ($cos/100));
        
        if (
    $qty != "") {
            
    mysql_query("INSERT INTO inventory VALUES ('', '".$pid."', '".$des."', '".$qty."', '".$cos."', '".$pri."', '".$ven."')");
        }
    }
    header("Location: index.php");
    ?>
    and index.php form:
    PHP Code:
            <form method="post" action="save.php">
                <?php
                $rows 
    25;
                for (
    $i 0$i $rows$i++) {
                echo 
    "\n";
                
    ?>
                <div class="invrow">
                    <input class="fqt" type="text" name="qtys[]">
                    <select class="fve" name="vendor[]">
                        <option>Blish</option>
                        <option>United</option>
                        <option>Orbit</option>
                        <option>Rainbird</option>
                        <option>CPI</option>
                        <option>National</option>
                        <option>Other</option>
                    </select>
                    <input class="fpi" type="text" name="pid[]">
                    <input class="fde" type="text" name="desc[]">
                    <input class="fco" type="text" name="cost[]">
                    <input class="fpr" type="text" name="price[]">
                </div>
                <?php
                
    }
                echo 
    "\n";
                
    ?>
                <input type="hidden" name="rows" value="<?=$rows;?>">
                <input type="hidden" name="time" value="<?=date("h:i");?>">
                <input type="submit" style="display: none;">
            </form>
    - the lid is off the maple syrup again!

  7. #7
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks notepad_coder.
    I will try it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •