SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Need help with editing each record one by one

    Ok, I am trying to write a cron job, using php, to run each day and update records in my database. First it checks to see if the trial membership period has ended (date format) and then it will update a field to "full member." I know all the code, but am not sure how to set a "loop" to go through and check each record, and update each record as so, if needed. Hope someone can help me. Hope I have been clear enough.

  2. #2
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you'd probably need to pull back the records that meet your criteria then loop thru that as if you were going to display them, instead of displaying them execute an update query... if you posted some code then we could give you an example.

  3. #3
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok, I made up all field names and things I don't know about your code, but this should give you an idea how to do this

    PHP Code:
    //connect to db first

    $sql "SELECT * FROM your_table WHERE your_condition";

    $result mysql_query($sql$db);

    if(
    $result == false)
        die(
    "Error...");
        
    if(
    mysql_num_rows($result) != 0)
    {
        while(
    $tmp mysql_fetch_assoc($result))
        {
            
    $sql "UPDATE your_table SET";
            
    $sql .= " Ful_membership = '1'";
            
    $sql .= " WHERE RecordID = '".$tmp["RecordID"]."'";
            
            
    mysql_query($sql);
        }

    -- Jelena --


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
  •