Solved

Find only database rows which have been ticked by checkbox

Posted on 2015-01-30
10
93 Views
Last Modified: 2015-01-31
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
Comment
Question by:damianb123
  • 4
  • 3
  • 3
10 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40580193
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
 

Author Comment

by:damianb123
ID: 40580201
The logistics of what is required I can do myself, it's the 'experts' help on the actual code - but thanks anyway!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40580238
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
 

Author Comment

by:damianb123
ID: 40580251
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40580362
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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40580832
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
 

Author Comment

by:damianb123
ID: 40580849
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40580929
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
 

Author Comment

by:damianb123
ID: 40581503
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40581559
Glad to help.  Thanks for the points and thanks for using E-E, ~Ray
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now