Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    how to skip an increment of 54 to insert in new db table

    Actually the question is based on the increment. But if anyone knows a better way of inserting table data into the database I'd like to hear it.

    I had saved a db table into html and am now seeking the precise coding to insert into my new db table.

    I modified by leaving out one field but adding another.

    First I did a for loop to get all the <th> tags which have the field names by storing them in an array. Then I used the count() of that array within another for loop which has all the <td>. The array of the <th> serves as a multiple like this:


    PHP Code:
    $allths = array();
    for(
    $th=0$tdh<count($allths); $td++){
        
    }
    for(
    $td=0$td<count($alltds); $td++){
        if(
    $td %==0){ //I'm not exactly sure how the exact code is since I'm away from my computer 
    //I think somewhere within the if statement I have to put count($allths)

        
    }

    I want to add the exception of one field or column, but insert the rest in their columns. Plus I have one column placed elsewhere in the db table (does it matter if it's not specified in order?)
    Compare bible texts (and other tools):
    TheWheelofGod

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    You can start the auto increment at 55 if you wanted. But one way I would say is to check the ID and if its 54, bypass it.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    how to skip an increment of 54 to insert in new db table


    Untested, might be syntax errors

    PHP Code:
    if ($td != 54) {
    // mysql insert query



    --------------
    Leonard Whistler

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $x = 1;
    $count = count($alltds);
    
    while ($x <= $count)
    {
        if ($x > 54) //Use this line if you want to skip the first 54 items.
        if ($x != 54) //Use this line if you want to skip just the 54th item.
        {
             [sql code here]
        }
        ++$x;
    }
    Last edited by MattF; 02-20-2010 at 08:25 PM.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    ok. I have the old db table in html format. I deleted the old db table though. I recreated with some new fields and gotten rid of one field which existed in the the old. I'm concerned over how to insert it in.

    PHP Code:
    $contents_of_page file_get_contents('saveddbtable/view_blinks1.php.htm');
    preg_match_all("#<th.*>(.+)</th#Ui"$contents_of_page$thInnerHTML);
    $contents_of_page file_get_contents('saveddbtable/view_blinks1.php.htm');


    $tdInnerHTML str_replace("></td>"">\"\"</td>"$contents_of_page);//to fill the blank tds otherwise it doesn't show

    preg_match_all("#<td.*>(.+)</td#Ui"$tdInnerHTML$tdInnerHTML);

    $ths=0;
    for(
    $tds=0$tds<count($tdInnerHTML[1]); $tds++){
        if(
    $ths<count($thInnerHTML[1])){
            
    $thInnerHTML[1][$ths] = array();
        }
        
        echo 
    $thInnerHTML[1][$ths]." = ".$tdInnerHTML[1][$tds]."<br />\n";
        
    $thInnerHTML[1][$ths][] = $tdInnerHTML[1][$tds];
        if(
    $ths==count($thInnerHTML[1])-1){
            
    $ths=0;
        }else{
            
    $ths++;
        }

    Is it possible (as I'm trying) to make a sub array by taking the array of fields from the <th> tags and store up the <td> arrays of data in each field?
    Compare bible texts (and other tools):
    TheWheelofGod


  •  

    Posting Permissions

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