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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing a single line from a database?

    Okay,

    I need to remove a name from a single database...
    a .db.

    I did this in PERL by putting the whole database in an array and then just using split() module to remove the one listing then wrote the array back to the database.

    How can I do the same thing in PHP???

    I've been trying to get it for 2 days now Im starting to loose my mind lol

    Any help is VERY appreciated!!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You are kidding right?

    You don't need to pull in all the records of the database. In your SQL statement you simply need to delete the record based on your criteria. What kind of database system are you using? MySQL?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey spook,

    see I am using .dbs

    The host my client is using doens't have MYSQL and they can't afford anything else so Im forced to use .dbs.

    Its onlyfor newsletters. So I just need to be able to remove one listing to get rid of a email.

    Yea I know lol
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Location
    USA
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by ACJavascript
    The host my client is using doens't have MYSQL and they can't afford anything else so Im forced to use .dbs.
    Last I checked MySQL was free...

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    MySQL is free,, Hosts are not...

    I think I could mabye use a mysql database on one my other servers... Hmm,, I might just do that...

    Anyways it would still be good to konw how to remove a line from a database.
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #6
    New Coder
    Join Date
    Nov 2003
    Location
    S.F.
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by ACJavascript
    MySQL is free,, Hosts are not...

    I think I could mabye use a mysql database on one my other servers... Hmm,, I might just do that...

    Anyways it would still be good to konw how to remove a line from a database.
    have you tried changing hosting company?
    there are no stupid questions, but there are stupid answers

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hahaha,

    They have already payed for a years worth on this host and dont want to change LOL....

    I am already going to use a MySQL database on my other server for this.... But I still wouldlike to know how to accomplish this.

    I found this code in a Mailing List Manager but it deson't work when I try to use it,, andy advice?


    PHP Code:
    $base_file = new csvfile;
            
    $base_file->name=$main_data_file;
                
    $base_file->init(); 
    I didn't add the rest of the script for actual remvoing the line, but I get a error on the new csvfile part.

    Any ideas?
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #8
    New Coder
    Join Date
    Nov 2003
    Location
    S.F.
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to specify to which host should php connect to, then you need to allow connection to that host, for that username from different hosts then localhost

    Code:
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, ALTER PRIVILEGES ON * . * TO "_your_username_"@ "www.someserver.net"
    there are no stupid questions, but there are stupid answers

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey DR.

    The code I showed was used to remove a listing from a text file.
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #10
    New Coder
    Join Date
    Nov 2003
    Location
    S.F.
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by ACJavascript
    Hey DR.

    The code I showed was used to remove a listing from a text file.
    oh Damn misunderstanding
    if you have a cvs file, then you might want to try to split it into array and then either insert into mysql database or work with it and suffer with it as is
    there are no stupid questions, but there are stupid answers

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    THey guys code was pretty simple, Didn't use any special codes except for hte cvs thing.

    Weird lol
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #12
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    what does a standard query to the db look like? I'm not familiar with DBS. If it's a flat file db, Then...


    Read in each line into array
    delete last element
    write array back to file

    I'd kinda have to know what exactly you use to access this...and what a dbs file looks like.

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey celtboy,

    Its named this for example:

    Test.db

    Its like test.txt or a test.dat.

    As for whats in it theres 1 email per line.

    Somthing@aol.com
    Somthing2@aol.com
    Somthing3@aol.com

    ect...

    Your idea is what I was thinking, just not sure out to do it.
    In Perl I place it all into a Array then use the module SPLIT to remove the on that equals the query. But I have no clue how to do that in PHP
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #14
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Ok, I'll try this really fast, without any error checking, testing, etc....


    PHP Code:
    <?

    function delete_line($what_to_delete) {

       
    $lines file("Test.db");
       foreach (
    $lines as $value)  {
             
    $value ereg_replace("\\r\\n","",$value); // need to remove the newline character...
             
    if ($value == $what_to_delete) {
                      
    // do nothing...we just won't write the line back
             
    } else {
                 
    $new_array[sizeof($new_array)+1] = $lines;
             }
       }
       
       
    $the_file fopen("Test.db","w");
       foreach (
    $new_array as $line) {
             
    fputs($the_file,$line "\\r\\n",1024);
       }
       
    fclose($the_file);

       return;

    }
    ?>


    That might work....

  • #15
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey CELTBOY!

    THat works except for one thing.

    Instead of writting back the actual values it writes them all back as Array...???

    It seems to work since when I remove one thers one missing from the count.

    So now its just getting the real values back into the database instead of Array.

    THANKS ALOT THOUGH I REALLY APPRECIATE IT
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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