Jump to content

coding/algorithm/best practise/design help required!


jasonlive
Go to solution Solved by mac_gyver,

Recommended Posts

i have a php page that is opened by a form. when opened it displays 100's of rows of data from a database.

what i need to do is have the user click on some rows, using either a link or a checkbox or something

and then submit to the database that "that row" is now "checked" or "flagged" or something. i added a column to the database "flag" with value 0 or 1.

also it is preferable to remain on same page after the database update. 

 

what would be the best way to do this?

 

-i have tried putting a checkbox in each row, but then i dont know how to build the query at the end to submit multiple rows (how to access each row's name/value)

 

-i then considered making each row a form itself...but seems bulky. (as i write this and wait for advice, im going to try this method it actually seems the easiest)

 

-i considered making each row a link....but then how do i submit a query from a link(using javascript?!)

Link to comment
Share on other sites

  • Solution

you would have one form that encompasses all the checkboxes. the name= ' ... ' attribute  of the checkbox form field would be an array, with a name that holds meaning for that field and the array index would be the id of the row from your database table - name='field[234]'

 

when the form is submitted, all the checked checkboxes will exist in the $_POST['field'] array, with the keys being the list of id's.

 

to set the database field value to a 1 for the checked checkboxes, you would use something like -

$ids = implode(',',array_keys($_POST['field']));
$query = "UPDATE your_table SET field = 1 WHERE id IN($ids)";

to set the database field value to a 0 for the unchecked checkboxes, you would use something like -

$ids = implode(',',array_keys($_POST['field']));
$query = "UPDATE your_table SET field = 0 WHERE id NOT IN($ids)";
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.