Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple php prob

  • 02-02-2004 2:13pm
    #1
    Banned (with Prison Access) Posts: 5,154 ✭✭✭


    Folks,
    When I add a record to a DB, say it's record 6, and delete the record. So far so food.
    But when I go to add a new one, it gets added as record 7, rather than replacing the record 6 which has just been deleted.

    What's the simplest way to resort the database or to get it to add a record into the first available slot?

    Cheers,
    S.

    (Using php5 with mySQL 4.0.16 on Apache)


Comments

  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    Err thats what an auto_increment field does, otherwise everytime you delete a row you'll have to manually subtract 1 from any rows of a higher id number.. equals pain in the ass... any particular reason you want to do this?


  • Banned (with Prison Access) Posts: 5,154 ✭✭✭Oriel


    Well, for tidiness sake more than anything else, I guess I could just live with it as it is. Say I'm creating a table of employees, I'd like to be able to automatically assign an employee number. I'd like the last employee number to reflect the number of employees currently in the table.
    Like I say, nothing too important, just wondering if there was an easy solution. Ah well. Thanks.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    I would think you'd be better off having a unique ID for each employee, and not recycling old numbers. Keep employee records accurate and all that.

    The query "SELECT COUNT(*) FROM table" should give you a count of the no. of employees in the table :)


  • Banned (with Prison Access) Posts: 5,154 ✭✭✭Oriel


    Actually folks, new question:

    What would be the simplest way to use checkboxes for recording handling? To explain what I mean, think of Hotmail interface, or the same way most web-based e-mail systems work. You know, where you select the item you want via a checkbox, then maybe perform a view, delete, amend, etc.

    Any ideas?


  • Closed Accounts Posts: 37 Arion


    When you want to use checkboxes you just put in a checkbox, and give it a name, and value.

    <input type="checkbox" name="whatever_you_want_to_call_it" value="whatever_value_you_want">

    Another tip I picked up recently, was that if you want to submit a choice of choice of two items, you can prefix the checkbox with a hidden field.

    Lets say you have the following form:

    <form action="whatever.php" method="post">
    <input type="hidden" name="att_name" value="att_val_if_UNchecked">
    <input type="checkbox" name="att_name" value="att_val_if_checked">
    <input type="submit" value="Submit">
    </form>

    Then if the box is unchecked, only the hidden field will be sent to PHP. If the box is checked. Then both will be sent to PHP, but since the checkbox, is send AFTER the hidden, it overrides the hidden value. This is however a hack.


  • Advertisement
  • Closed Accounts Posts: 37 Arion


    Actually now that I've re-read your question:

    I'd use indexed checkboxes. By this I mean using something like

    <input type="checkbox" name="del[]" value="1"> rest of info here for this row
    <input type="checkbox" name="del[]" value="2"> rest of info here for sec row


    Then on the PHP side, $_POST would be an array of the checkboxes checked.

    Having that said, there are many different ways of handling that situation. They are all different though.


  • Banned (with Prison Access) Posts: 5,154 ✭✭✭Oriel


    Yeah, see I'll need each of the check boxes to be different (.i.e indexed), but I need an way to do this automatically, since I'll just be dumping the contents of the table onto the screen and letting the user choose which the way want use. So I can't be writing the html for the checkboxes manually.

    For example, I'd show the list of names currently stored on the database, with a text box beside each one. The user would choose one and click "amend" button, which would pass the keyfield of that record to "amend.php". This file would lookup the keyfield and then display all the attribuates for that user in a form, with the attributes filled in and ready to be changed.

    I'm going to do a bit more research on this now, but from what I've seen, it's not easy to get a lot of info on this.

    Like you say there's probably serveral ways to go about this, so any other ideas?


  • Closed Accounts Posts: 37 Arion


    Yeah, see I'll need each of the check boxes to be different

    Why?

    take a look at the following
    [PHP]
    <?php

    $my_arr = array();

    $my_arr[] = "goat";

    print_r($my_arr);

    $my_arr[] = "cow";

    print_r($my_arr);

    ?>
    [/PHP]

    In the same way, if you have checkboxes, like:(I've left out the type="checkbox" part)

    <input name="del[]" value="1"> ...
    <input name="del[]" value="2"> ...
    <input name="del[]" value="3"> ...

    And check them all, You'll get an array called $_POST containg 1, 2, and 3

    If you want to index them, you can just

    <input name="del[first_index]" value="first_val">
    <input name="del[other_index]" value="second_val">

    And you'll get an array $_POST containing
    array('first_index' => 'first_val', 'other_index' => 'other_val')


Advertisement