• supernova42

    (@supernova42)


    I’m using a loop to modify some of my field values.
    I’m looping from an id=1 up to an arbitrary value of 1000.
    Rather than using the arbitrary value of 1000, is there a way I can determine the maximum value of id that is currently in place in PDB.

    for($i=1; $i<=1000; $i++) {
    $data=Participants_Db::get_participant($i);
    $user_id = $data[‘id’];
    $username = $data[‘username’];
    $boatname = $data[‘boat_name’];
    if(!empty($username)) {
    if (empty($boatname)) {
    echo $username.’:’.$boatname.'<br>’;
    $data = array();
    $data[‘id’]=$user_id;
    $data[‘username’]=$username;
    $data[‘boat_name’]=’Name Needed’;
    Participants_Db::write_participant($data);
    }
    }
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Certainly, you can use a db query to the database to get a sorted list of all the ID values, then take the top value. That will be far more efficient than trying to loop through all the records.

    If you’re familiar with using the WordPress wpdb class, this is very simple.

    Thread Starter supernova42

    (@supernova42)

    Simple for you Roland, but it didn’t look that simple to me. I will check it again after the effects of this bottle of wine have worn off.

    What is the actual significance of Record_ID (id) and what is it used for?
    Could I for example run a php routine to go through all my PDB records and rename the Record_ID (id) starting from say 1. It would finish at the number equivalent to the number of records in the database. Would this work or would it mess up the database?

    The other thing I keep meaning to ask is, What is the Private_ID used for as it appears to be made up of a random block of characters.

    I know you’ve heard this many times before but this is definitely the best plugin on WordPress.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    You probably don’t want to change the record id value: it is used internally to identify a particular record. The number of records is also easy to get, no need to renumber for that. But you do need to be familiar with how to make simple database queries. I suggest you read the WordPress documentation on using the wpdb class, it makes this quite simple.

    For example:

    <?php
    global $wpdb;
    $record_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . Participants_Db::$participants_table );
    ?>

    The Private ID is used to generate a private link to an individual record for editing.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Maximum value of ID being used’ is closed to new replies.