• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 101
  • Last Modified:

Find only database rows which have been ticked by checkbox

Hi,
   I am looking to output a series of rows of data from my database, then have a tick box on each row which can be ticked.  Once the tick boxes have been ticked, a button is pressed which then ONLY leaves or displays the ticked records - a sort of compare mechanism....

Can anyone help me out?

Cheers in advance.

D
0
damianb123
Asked:
damianb123
  • 4
  • 3
  • 3
1 Solution
 
COBOLdinosaurCommented:
You just need a CSS class with display:none.

Then for the click event on the buttun you just fire a script to iterate through the checkboxes and change the className property to the class with display:hidden where the checkbox checked property is false.

Changing the className value is much more efficient then changing the style properties directly through the style property.

Cd&
0
 
damianb123Author Commented:
The logistics of what is required I can do myself, it's the 'experts' help on the actual code - but thanks anyway!
0
 
COBOLdinosaurCommented:
You post a high leve description with no code or structual detail and you expect us to fetch you code out of thin air without having any context? Interesting.

To begin with we are here to help you find solutions, not do your work for you.  If you need sample code then you should post what you have so we can give you the hooks or modifications you need.

Cd&
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
damianb123Author Commented:
You know what I only came back to this site recently to get help from 'experts' - it used to be very good.....  I don't think I've had a single question answered as yet, you seem to comment on them all, with nothing constructive to say!  Please stop commenting on my questions.....  I haven't seen anything which makes me think you know much more than me!!!
0
 
COBOLdinosaurCommented:
Sorry to hear you are not having a good experience on the site.  As you have indicated you are not interested in my help, I wiil avoid your questions, please point out my mistake if I post in one of your questions. I volunteer to help on EE and there are enough members happy to do things the way I prefer them because they get the solutions they need.

Perhaps you fail to understand the relationship.  You are not the boss and you have absolutely no power or right to make demands on volunteer Experts who or may not decide to offer help.

If you want to improve your experience on EE and other tech support sites you might try understanding the relationships on Q/A sites.

Cd&
0
 
Ray PaseurCommented:
See if this article is helpful.  It uses links instead of checkboxes, but the concepts are pretty close
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html

For your checkbox application you will want to create an array of values in the checkboxes, so the checkboxes will be named something like this.  The value of $id will be the auto_increment key of the row that you want to identify.  You can get these keys from a standard SELECT query, and you can use the query results set to build your HTML form.

<input type="checkbox" name="box[$id] />

When the HTML form is submitted you will be able to find the checked boxes by using var_dump() to print out the contents of the $_REQUEST variable.

If I have a chance later I may be able to show you an example, but before I do that, please read the article and post any questions you have about it back here.

Best regards, ~Ray
0
 
damianb123Author Commented:
Ray,
     Many thanks for this, i managed to get it working for a single value which is ticked by using the checkbox array, the trouble is if i have more than one row ticked then the array just looks like a string of numbers ie 2456, rather than 2,4,5,6, so when i perform my select statement it will only work for single checkbox ticks.  How can i change it so my select statement perform a WHERE ID = 2,4,5,6???

I hope that makes sense.

Thanks for your help.  Much appreciated.
0
 
Ray PaseurCommented:
This will be a bit of a challenge, since my hosting provider is down and I cannot test anything right now, but I'll try to show a general design pattern that could get you somewhat closer.  Please see if this makes sense.

<?php // demo/temp_damianb123.php

/**
 * SEE http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28607205.html
 */
error_reporting(E_ALL);


// IF THERE IS A POST REQUEST
if (!empty($_POST['box']))
{
    // SHOW THE REQUEST DATA
    var_dump($_POST);

    // COLLAPSE THE BOX PORTION INTO SOMETHING COMMA-SEPARATED THAT CAN BE USED IN A QUERY
    $boxin = implode(',', $_POST['box']);
    $query = "SELECT cols FROM table WHERE id IN ( $boxin )";
    var_dump($query);
}
// END OF ACTION SCRIPT


// PUT UP A FORM WITH THE NUMERIC VALUES OF THE DATABASE "$id" COLUMNS
$form = <<<EOD
<form method="post">
<input type="checkbox" name="box[]" value="1" /> One<br>
<input type="checkbox" name="box[]" value="2" /> Two<br>
<input type="checkbox" name="box[]" value="3" /> Three<br>
<input type="checkbox" name="box[]" value="4" /> Four<br>
<input type="submit" />
</form>
EOD;

echo $form;

Open in new window

0
 
damianb123Author Commented:
Thanks so much Ray, after a bit of learning on the implode routine (very handy to know) it works a treat.... many thanks for all your help with this.

Damian
0
 
Ray PaseurCommented:
Glad to help.  Thanks for the points and thanks for using E-E, ~Ray
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now