SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: Rotary System

  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rotary System

    Hi,

    I currently have a database with two columns containing numbers 1 through 9.
    Using PHP, how do I randomly assign a number from column 1 to a non-identical number in column2?

    Random Example: Incorrect

    11
    22
    33...

    Random Example: Correct

    19
    28
    37...

    Many Thanks,
    TicTac

  2. #2
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this maybe:

    PHP Code:
    $numberOne 1;
    $numberTwo $numberOne;

    while ( 
    $numberTwo == $numberOne ) {
      
    $numberTwo /* retrieve random row here */
    }

    /* assign numberOne to numberTwo here */ 

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can I see some code to work around it?

    This is how I would go about it:

    select one number from the database which doesn't have a column 2 value. Then, requery the database like this ($originalNumber is the number you selected before):
    PHP Code:
    mysql_query("SELECT `Column1` FROM `yourtable` WHERE `Column1` != '[$originalNumber]' ORDER BY RAND()"); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have any code to hand, but I can give you a bit more of an idea on what I'm trying to do?

  5. #5
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, column 1 contains numeric numbers (1-9), well as column 2 contains word number (One-Nine). But these values will be made changeable if necessarily, at a later date.

    How do I randomly assign a numeric number (Column 1), to a word number (Column 2)?
    Last edited by TicTac; Aug 21, 2007 at 10:47.

  6. #6
    Non-Member
    Join Date
    Aug 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm interested in TicTac's idea, is it possible?

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use shuffle(), Documentation @ :
    http://us3.php.net/manual/en/function.shuffle.php
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  8. #8
    Non-Member
    Join Date
    Aug 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you give me an example?

  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $array_2 = array( => "zero",
                        
    => "one",
                        
    => "two",
                        
    => "three",
                        
    => "four",
                        
    => "five",
                        
    => "six",
                        
    => "seven",
                        
    => "eight",
                        
    => "nine"
                    
    );
                        

    shuffle$array_2 );
    print_r$array_2 ); 
    Yields : Array ( [0] => eight [1] => seven [2] => zero [3] => nine [4] => six [5] => one [6] => two [7] => four [8] => five [9] => three )
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  10. #10
    Non-Member
    Join Date
    Aug 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Daily Job Rotary System

    Hi,

    Using PHP, how do I go about making a Random Job Rota System (RJRS), where all daily jobs are stored in a MySQL Database, and randomly assigned to different members of staff throughout the week,

    Depending on how many staff are working on a particular day, some staff may have 2-3 jobs more than others. Resulting in less jobs for those people the following day.

    Eventually everybody should have done the same jobs as everybody else, unless a job has been specifically set for certain people only, due to staff skills.

    Many Thanks,
    F10

  11. #11
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may take a look at phptimesheet
    my mobile portal
    ghiris.ro

  12. #12
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    threads merged

    please, only one thread per topic
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  13. #13
    Non-Member
    Join Date
    Aug 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rotary System

    How could something like that be made?


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
  •