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

table rows with checkboxes in PHP

Options
  • 30-09-2005 9:11pm
    #1
    Registered Users Posts: 1,086 ✭✭✭


    I am using PHP and after I return a search query from the database I display each result as a table row in HTML. In the administration search results I want to have checkboxes in each row with a select all / none functionality. With this I want to be able to use the selected rows to delete or modify. Similar to Gmail where you can move selected rows to trash. How is this done? How do I insert that into my PHP code. Do I have to display the results in a form?

    This is my current code displaying the results. It has no functionality.


    $i=0;
    while ($i < $num) {

    $name=mysql_result($result,$i,"name");
    $description=mysql_result($result,$i,"description");
    $picturelink=mysql_result($result,$i,"picturelink");
    $price=mysql_result($result,$i,"price");
    $category=mysql_result($result,$i,"category");
    $id=mysql_result($result,$i,"id");
    echo "<tr>";
    echo "<td> $id<br></td>";
    echo "<td> $name<br></td>";
    echo "<td> $description<br></td>";
    echo "<td> $category<br></td>";
    echo "<td> $price<br></td>";
    echo "<td> $picturelink<br></td>";
    echo "<tr>";

    $i++;
    }


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Using this script as a template, get your maximum number by placing the number of rows returned in the loop. Then when you are writing the table, add an extra row with a number as the name.
    echo "<input type=checkbox name=C". $1 ." checked>"
    


  • Registered Users Posts: 6,494 ✭✭✭daymobrew


    Peter B wrote:
    I am using PHP and after I return a search query from the database I display each result as a table row in HTML. In the administration search results I want to have checkboxes in each row with a select all / none functionality. With this I want to be able to use the selected rows to delete or modify. Similar to Gmail where you can move selected rows to trash. How is this done? How do I insert that into my PHP code. Do I have to display the results in a form?
    I believe the select all/none stuff will be done by Javascript (look at the Gmail source for ideas).

    Yes, you'll have to put the results inside a form so that the checkbox data can be submitted. The 'Delete' and 'Modify' buttons will be your 'submit' buttons, just with different values so the receiving script knows what to do.

    I would give the checkboxes names like 'check_XXX' where XXX is a unique value associated with the item. I don't think $id will be useful, unless this in the database, more likely use $name, if that is a primary key. Of course the primary key could be a column not in the code you provided.

    A simpler way could be to have 'Delete' and 'Modify' links (not buttons) that use a GET method e.g. the link would be something like $PHP_SELF."?del=$name". No forms, no checkboxes and you only ever have to deal with one item at a time. Now, where you send the user after the deletion/modification is a different store (maybe rerun their query)


Advertisement