Solved

Find only database rows which have been ticked by checkbox

Posted on 2015-01-30
10
95 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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
 
LVL 109

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 109

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 109

Expert Comment

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

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 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