Results 1 to 3 of 3

Thread: Insert row in a mysql Database

  1. #1
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Insert row in a mysql Database

    I have:

    PHP Code:
    <select name="year" id="year" tabindex="3"> 
                                        
                                        <option value="<? echo date('Y'); ?>"> 
                                                      <? echo date('Y'); ?> 
                                                     
                                         </option> 
                                         
                                        <option value="<? echo date('Y')-1?>"> 
                                                      <? echo date('Y')-1?> 
                                         </option> 
                                         
                                        <option value="<? echo date('Y')-2?>"> 
                                                      <? echo date('Y')-2?> 
                                         </option> 
                                         
                                      </select>
    to list 3 years


    And I want to correspond a number of documents for year to insert to a mysql DB:


    PHP Code:
    PHP Code:
    <?php 
                         
                            $sql 
    "select MAX(number)+1 as mynumber from actas2 where year=year(now());";  
                            
    $query mysql_query($sql);  
                            print 
    mysql_error();  
                            
    $arr2 mysql_fetch_object($query); 
                         
                         
                        
    ?>  
                         
                        <p><? echo $arr2->mynumber?></p>  
                        <input type="hidden" name="number" value="<? echo $arr2->mynumber?>">
    How I will join this two parts for insert?????

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Firstly, the above code can be simplified to:
    Code:
                                      <select name="year" id="year" tabindex="3">
                                        <?php for($i=0;$i<3;$i++) { ?>
                                          <option><?php echo(date('Y') - $i); ?></option>
                                        <?php } ?>
                                      </select>
    Secondly, I'm not entirely sure what you want to do, but to insert the year into the table, you'd use:
    Code:
    INSERT INTO actas2 (year) VALUES ($year);
    ... where $year is a defined year and actas2 is the table.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You&#180;d understand me!!!

    I want to insert the year and a number of document at the same time. If there are documents in DB of any year , it selects the last number e adds plus one.

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
  •