SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 40

Thread: Php

  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php

    Can Anyone help me make a PHP Banker's Algorithm..im really got hard time making it can you please help me..
    The need is you must input number of Columns and Rows..
    the Out put must be Allocation, Max, Need, and Work



    T_T

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums.

    I don't understand what you're asking. Could you explain a bit more?

  3. #3
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Welcome to the SP forums.

    I don't understand what you're asking. Could you explain a bit more?
    Banker's Algorithm..Bankers Algo.txt
    First you need to input number of Rows and Columns
    the rows and columns must have its unique ID/name

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    While we wait for approval for the attachment, how about you show us what you've got so far?

    We will help you get there, but we're not here to do it for you.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    And which part of the Banker's Algorithm are you trying to demonstrate? A state's safety?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    And which part of the Banker's Algorithm are you trying to demonstrate? A state's safety?

    it's Deadlock Avoidance

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    So "Given Safe State A, and Request R, demonstrate the system's correct response".

    Talk me through the logic of what the system should do.
    (Yes, I know how to google, but I want you to spell it out, so you can take each step and put it into code)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    So "Given Safe State A, and Request R, demonstrate the system's correct response".

    Talk me through the logic of what the system should do.
    (Yes, I know how to google, but I want you to spell it out, so you can take each step and put it into code)
    1: You are going to input the Rows which is the Process
    2: You are going to input the Columns which is the Reourse
    3: You are going to Input the said Given Resource like if you enter 3 resource there must 3 reourse A= 9,B= 6,C= 4
    4: If the Resource is 3 blocks/textarea there must be 3 textare in each Alocated , Max, Need, and Work/Availability
    5: When it is displayed you are going to input value in the Allocated and Max Textfield
    6: In the Need Textfield the Formula is that the Need is equal to Max minus(-) Allocated
    7: In the Availability You need to find the first resource which you are going to add all the Resource A in the Allocated, Resource B in the Allocated, Resource C in the Allocated then subtracted to the Given Resource which is A is equal 9 subtracted to the total Resource A up to B
    8: When you find the First Availability you are going to find the least value in the Need, if you find it you are going to add the first Availability to the value of the Allocated.

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Okay, so, 1-6 describes your setup. Pretty simple stuff there.
    You dont really seem to have a "If Process X requests Y resources of type Z, will the system accept or reject it" statement in there.
    7-8 seem to be testing for a Safe State, but that doesnt demonstrate deadlock avoidance, it just tests the current state.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a Code here but i can't do the exact settings that must be display

    <html>
    <form name="bank" method='post' action='Start.php'>
    Enter Resources: <input type='text' name='resource' size='3'><br>
    Enter Process &nbsp;&nbsp;&nbsp;: <input type='text' name='process' size='3'><br>
    <input type='submit' value='Submit'><br>
    <?php
    $x = $_POST['resource'];
    $y =$_POST['process'];
    //$count = 0;
    for($i=0; $i<= $x; $i++)
    {

    echo "Instance $i = "."<input type='text' size='2' name='r'>"." ";
    }
    if($y !=null){
    echo"<br><b>Allocation</b><br>";
    echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    for ($ctr3=1;$ctr3<=$y;$ctr3++) {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R ".$ctr3."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    for ($ctr=1;$ctr<=$y;$ctr++) {
    echo "<br> P ".$ctr;
    for ($ctr2=1;$ctr2<=$y;$ctr2++) {
    //$array[$ctr1][$ctr2];
    echo "<input type='text' name='input' size='5'>";
    //$count++;
    //echo " R ".$ctr2;
    }}
    }

    ?>
    </form>
    </body>
    </html>




    The code is still lack the Max, Need and Availability
    and I can figure out how to do it.

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    The easiest solution is going to be the following:

    Display text boxes for #R, #P, RequestR, and RequestP. (Number of Resources, Number of Processes, the test Request Resource, and the test Request Process. I'm assuming a request size of 1, but if you want to add that as a variable, make that a text box too)
    Display text areas for ResourceMax Max and Allocated. The other two values are derived from these numbers (Need = Max - Allocated, Availability = ResourceMax - Sum(Allocated)) and should not be entered by the user.

    Next is to take that form data, sanity check it (make sure the input is complete and valid), then run the Algorithm logic to determine whether the request should be granted or denied (and probably display WHY)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  12. #12
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    The easiest solution is going to be the following:

    Display text boxes for #R, #P, RequestR, and RequestP. (Number of Resources, Number of Processes, the test Request Resource, and the test Request Process. I'm assuming a request size of 1, but if you want to add that as a variable, make that a text box too)
    Display text areas for ResourceMax Max and Allocated. The other two values are derived from these numbers (Need = Max - Allocated, Availability = ResourceMax - Sum(Allocated)) and should not be entered by the user.

    Next is to take that form data, sanity check it (make sure the input is complete and valid), then run the Algorithm logic to determine whether the request should be granted or denied (and probably display WHY)


    Yeah that's it..

    can you help me make the Syntax i got error on my syntax..

  13. #13
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Everything in the first paragraph is pure HTML, no PHP involved. Generate that first. Then we'll move on to step 2 (Sanity Check), and Step 3 (Algorithm).
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  14. #14
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    The easiest solution is going to be the following:

    Display text boxes for #R, #P, RequestR, and RequestP. (Number of Resources, Number of Processes, the test Request Resource, and the test Request Process. I'm assuming a request size of 1, but if you want to add that as a variable, make that a text box too)
    Display text areas for ResourceMax Max and Allocated. The other two values are derived from these numbers (Need = Max - Allocated, Availability = ResourceMax - Sum(Allocated)) and should not be entered by the user.

    Next is to take that form data, sanity check it (make sure the input is complete and valid), then run the Algorithm logic to determine whether the request should be granted or denied (and probably display WHY)
    This is the current HTML and PHP i have made and I cant figure out the Element of each textfield or its unique ID..
    can you help me do it



    <html>
    <head></head>
    <body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    Enter number of rows <input name="rows" type="text" size="4">
    and columns <input name="columns" type="text" size="4"> <input type="submit" name="submit" value="Draw Table">
    </form>

    <?php

    $columns = $_POST['columns'];
    for($i=1; $i<= $columns; $i++)
    {

    echo "Instance $i = "."<input type='text' size='2' name='r'>"." ";

    }
    if (isset($_POST['submit'])) {

    // set variables from form input
    $rows = $_POST['rows'];
    $columns = $_POST['columns'];
    // loop to create rows
    for ($r = 1; $r <= $rows; $r++) {
    echo "<br>";
    // loop to create columns
    for ($c = 1; $c <= $columns;$c++) {
    echo "<input type='text' name='input' size='5'> ";
    } echo "<br> ";
    }
    echo "</table> ";
    }

    ?>

    </body>
    </html>

  15. #15
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Those text fields dont have a unique identifier, so it's no wonder you cant figure them out.

    What this code is trying to do is trying to generate the correct number of input boxes given input in a prior step (which may change in the following step, because those fields do not become uneditable) If you really want to do this, then you'll have to start making your inputs into arrays (tacking [] onto the names, and probably $i in a couple of places too).
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  16. #16
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Those text fields dont have a unique identifier, so it's no wonder you cant figure them out.

    What this code is trying to do is trying to generate the correct number of input boxes given input in a prior step (which may change in the following step, because those fields do not become uneditable) If you really want to do this, then you'll have to start making your inputs into arrays (tacking [] onto the names, and probably $i in a couple of places too).


    Awts T_T
    can you help me about the syntax please badly needed for the assignment...

  17. #17
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    echo "Instance $i = "."<input type='text' size='2' name='r'>"." ";

    echo "Instance $i = "."<input type='text' size='2' name='r[]'>"." ";

    now it's an array.
    echo "<input type='text' name='input' size='5'> ";
    echo "<input type='text' name='input[".$row."][".$column."]' size='5'> ";

    Now it's a two dimensional array. (You coudl reverse row and column if you want, the order isnt important, so long as you remember which order you did it in.)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  18. #18
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    echo "Instance $i = "."<input type='text' size='2' name='r'>"." ";

    echo "Instance $i = "."<input type='text' size='2' name='r[]'>"." ";

    now it's an array.
    echo "<input type='text' name='input' size='5'> ";
    echo "<input type='text' name='input[".$row."][".$column."]' size='5'> ";

    Now it's a two dimensional array. (You coudl reverse row and column if you want, the order isnt important, so long as you remember which order you did it in.)

    i've got what you mention, my problem now is that how can make another textfield where i am going to the value of Max
    and how can I make a textfield where the output of Need and Work be placed..

    do I need to make the

    for ($c = 1; $c <= $columns * 4;$c++) {
    echo "<input type='text' name='input[".$rows."][".$columns."]' size='5'> ";
    } echo "<br> ";


    for it to have a 4 parts textfield this the code so far


    <html>
    <head></head>
    <body>
    <form method="post" action="OS.php">
    Enter number of rows <input name="rows" type="text" size="4">
    and columns <input name="columns" type="text" size="4">
    <input type="submit" name="submit" value="Draw Table">
    </form>

    <?php

    $columns = $_POST['columns'];
    for($i=1; $i<= $columns; $i++)
    {

    echo "Instance $i = "."<input type='text' size='2' name='r[]'>"." ";

    }
    echo"<br>Alocation Max Need Work";
    if (isset($_POST['submit'])) {

    // set variables from form input
    $rows = $_POST['rows'];
    $columns = $_POST['columns'];
    // loop to create rows
    for ($r = 1; $r <= $rows; $r++) {
    echo "<br>";
    // loop to create columns
    for ($c = 1; $c <= $columns;$c++) {
    echo "<input type='text' name='input[".$rows."][".$columns."]' size='5'> ";
    } echo "<br> ";
    }
    echo " ";
    }





    ?>

    <br>
    <br><input type="submit" name="sumit" value="Submit">
    <input type="reset" name="Reset">
    </body>
    </html>

  19. #19
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    This is going to be what I call 'gated'. Several pageloads of the same page.

    Pageload 1: Request #Resources and #Processes in the current state
    Pageload 2: Request the Available resources, and the current state's Allocations & Max. Can also request to know what the test-Request is at this point.
    Pageload 3: Do the algorithm for that Request, and output the results.

    a nested For (row x column) will get you the correct number of text fields, you'll just have to do it twice (once for Allocations, and once for Max). You'll also need to run a For (column) to get the Available.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  20. #20
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    This is going to be what I call 'gated'. Several pageloads of the same page.

    Pageload 1: Request #Resources and #Processes in the current state
    Pageload 2: Request the Available resources, and the current state's Allocations & Max. Can also request to know what the test-Request is at this point.
    Pageload 3: Do the algorithm for that Request, and output the results.

    a nested For (row x column) will get you the correct number of text fields, you'll just have to do it twice (once for Allocations, and once for Max). You'll also need to run a For (column) to get the Available.

    so like this

    for ($r = 1; $r <= $rows; $r++)
    {
    for ($c = 1; $c <= $columns;$c++) {

    echo" ".$input[input[".$r."][".$c."]];
    }

  21. #21
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    if your input is formed in a method='post' form as:
    <input type='text' name='input[$r][$c]'>

    then the value passed (once the form is submitted) should be referenced as
    $_POST['input'][$r][$c]
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  22. #22
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    if your input is formed in a method='post' form as:
    <input type='text' name='input[$r][$c]'>

    then the value passed (once the form is submitted) should be referenced as
    $_POST['input'][$r][$c]

    as you can see im going to in put 2 on colms and 2 in rows

    for ($c = 1; $c <= $columns * 4;$c++) {
    echo "<input type='text' name='input[".$rows."][".$columns."]' size='5'> ";
    } echo "<br> ";


    the colums is multiplied by four so in the 3rd and 4th textfield it is the Max
    then the 5th and 6th textfield is the Need so im going to make it like this

    $_POST['input'][1][5] = $_POST['input'][1][1] - $_POST['input'][1][3];

    is it correct ??

  23. #23
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    I would not do that. Seperate them into different arrays (you're trying to put them all into the 'input' array).
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  24. #24
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    I would not do that. Seperate them into different arrays (you're trying to put them all into the 'input' array).

    how? i cant figure out the answer T_T

  25. #25
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Real quick like:
    Code:
    <?php
    
    $columns = $_POST['columns'];
    for($i=1; $i<= $columns; $i++)
    {
    
    echo "Instance $i = "."<input type='text' size='2' name='r[]'>"." ";
    
    }
    echo"<br>Alocation Max Need Work";
    if (isset($_POST['submit'])) {
    
    // set variables from form input
    $rows = $_POST['rows'];
    $columns = $_POST['columns'];
    // loop to create rows
    for ($r = 1; $r <= $rows; $r++) {
    echo "<br>";
    // loop to create columns
    for ($c = 1; $c <= $columns;$c++) {
    echo "<input type='text' name='input[".$r."][".$c."]' size='5'> ";
    } echo "<br> ";
    }
    echo " ";
    }
    ?>
    The green section creates your ResourceMax section.
    The red section creates -1- of your inputs (lets say Allocation, because that came first in the list). Copy and paste the red code again below it, change 'input' to something else, say 'max'. Now you've got spaces for your Allocated, and your Max. Need and Available dont need to be filled in by the user because they are calculated, so dont display anything for those.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •