need a little quick help

Discussion in 'PHP' started by jfontestad, Dec 15, 2008.

  1. #1
    i need some help.

    i have a database and need some help in writing a quick script that will:
    1)for each row grab the data from a given field.
    2)pass is through a function (strips all spaces and wild characters)
    3)inserts it into designated field.

    i'm sort of stuck because i don't know where to start. :\

    is there a simple way to do this?
     
    jfontestad, Dec 15, 2008 IP
  2. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #2
    This is what I have come up with, but it is taking FOREVER...

    
    <?php
    
    include_once("db_connect.php");
    
    $q = mysql_query("SELECT user FROM users");
    
    while($results = mysql_fetch_object($q)) { 
    	$user = $results->user;
    	$user_convert = urlconvert($results->user);
    	$q1 = mysql_query("UPDATE users SET url_user = '".$user_convert."' WHERE user = '".$user."'");
    }
    mysql_close($q);
    	echo "Done!";
    ?>
    PHP:
    urlconvert simply strips all spaces and add _ as well as periods and stuff like that.

    Anyone have a better method? Because this is taking forever!
     
    jfontestad, Dec 16, 2008 IP
  3. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    1)for each row grab the data from a given field.

    select * from <Table_name> where <row_name>="user_name";

    2)pass is through a function (strips all spaces and wild characters)

    $row_num1="Samir $ % UK #@ ";
    $row_num2="United State Of America ! * PHP";
    $special = array('/','!','&','*','%','-',' ','@','%','#'); // you can add whatever u want to remove from
    $new_row_num1 =str_replace($special,'',$row_num1); //$new_row_num1=SamirUK
    $new_row_num2 =str_replace($special,'',$row_num2); //$row_num2=UnitedStateOfAmericaPHP

    3)inserts it into designated field.

    $q1 = mysql_query("UPDATE users SET url_user = '".$new_row_num1."' WHERE user ='".$user."'");

    let me know if you ahve any Question regarding PHP script.
     
    ksamir2004, Dec 16, 2008 IP