Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array Manipulation

    Hiya Everyone,

    Using the following code, how do I load all information from the database into an array ($records), and display each record on screen with it's own delete button.

    Then when a delete button is clicked, all records NOT including the record that had the button clicked should get copied into a separate array ($temp).

    Then all record from the $temp array should get copied into the database, overwriting everything that was there previously.

    Code:
     <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
    {
      die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("WB", $con);
    
    $result = mysql_query("SELECT * FROM Birds");
    
    if(mysql_error() != 0 || mysql_num_rows($result) == 0)
    {
      die("No database, or no data");
    }
    
    $records = array();
    while($row = mysql_fetch_object($result))
    {
      array_push($records, $row);
    }
    
    // Loop the following code
    
    echo $records[0]->Name;
    echo $records[0]->Species;
    echo $records[0]->Sex;
    ?>
    How can this be done?

    Is there anyway of using a loop and a counter variable to display all the records, instead of manual declaring the "Numeric Array Store" value etc.

    Many Thanks,
    Last edited by Salchester; 06-28-2007 at 07:10 PM.

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why don't you just delete the record that you pressed the button to delete in the first place?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •