mkr365 Posted April 6, 2008 Share Posted April 6, 2008 Hello, I have a site where you can select for example a "categorie", after the selection (option value) the information is from my database. Next problem: At the moment i'm using option value's but i really want to use checkboxes. I'v tried to changed my code so that the checkboxes are active, but they aren't working. Is it difficult to change this? Or can somebody see something is wrong in my code? The original code with option value (which is working fine): [color=red]<tr><td>Rubriek:</td><td><select name="categorien"><option value="">Selecteer...</option>'; $sql = "SELECT * FROM rubrieken INNER JOIN groepen ON rubrieken.GroepID = groepen.GroepID WHERE Groepnaam = 'Architect' ORDER BY Rubrieknaam "; $result = mysql_query($sql) or die(mysql_error()); while($query = mysql_fetch_array($result)) { if ($_GET['categorien'] == $query['RubriekID']) echo '<option value="'.$query['RubriekID'].'" selected>'.$query['Rubrieknaam'].'</option>'; The code which i tried to change: [color=red]<tr><td>Rubriek:</td><td><select name="categorien"><option value="">Selecteer...</option>'; $sql = "SELECT * FROM rubrieken INNER JOIN groepen ON rubrieken.GroepID = groepen.GroepID WHERE Groepnaam = 'Architect' ORDER BY Rubrieknaam "; $result = mysql_query($sql) or die(mysql_error()); while($query = mysql_fetch_array($result)) { if ($_GET['categorien'] == $query['RubriekID']) echo '<input type="checkbox"'.$query['RubriekID'].'" selected>'.$query['Rubrieknaam'].''; else echo '<input type="checkbox"'.$query['RubriekID'].'" >'.$query['Rubrieknaam'].''; } echo '</select></td></tr> <tr><td colspan="2"><input type="submit" value="zoeken"><input type="hidden" name="zoek" value="true"></td></tr> else echo '<option value="'.$query['RubriekID'].'" >'.$query['Rubrieknaam'].'</option>'; } echo '</select></td></tr> <tr><td colspan="2"><input type="submit" value="zoeken"><input type="hidden" name="zoek" value="true"></td></tr>[/color][/color] Link to comment Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 use "checked", not "selected" for checkboxes Link to comment Share on other sites More sharing options...
mkr365 Posted April 8, 2008 Author Share Posted April 8, 2008 Well iv'e changed it to "checked" but with no result. Can it be something else? If i check a checkbox i get no results, i recon its a configuration issue. Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 You need to brush-up on your HTML checkboxes need name and value attributes echo '<input type="checkbox" name="categorien[]" value="{$query['RubriekID']}" selected>'.$query['Rubrieknaam'].''; checkboxes don't have select.../select tags around them Only checked checkbox values are posted. Link to comment Share on other sites More sharing options...
mkr365 Posted April 8, 2008 Author Share Posted April 8, 2008 Cool, that helped me a lot further! It's almost working The search works just fine now but I can only search for 1 checkbox, if i select multiple checkboxes than I see only the results from the last one selected. Is there some way to show the results for multiple selected checkoboxes? <tr><td>Rubriek:</td><td>'; $sql = "SELECT * FROM rubrieken INNER JOIN groepen ON rubrieken.GroepID = groepen.GroepID WHERE Groepnaam = 'Architect' ORDER BY Rubrieknaam "; $result = mysql_query($sql) or die(mysql_error()); while($query = mysql_fetch_array($result)) { if ($_GET['categorien'] == $query['RubriekID']) echo '<input type="checkbox" name="categorien" value="'.$query['RubriekID'].'" checked>'.$query['Rubrieknaam'].''; else echo '<input type="checkbox" name="categorien" value="'.$query['RubriekID'].'">'.$query['Rubrieknaam'].''; } echo '</select></td></tr> <tr><td colspan="2"><input type="submit" value="zoeken"><input type="hidden" name="zoek" value="true"></td></tr> Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 use name="categorien[]" then they are posted as an array foreach ($_POST['catogorien'] as $cat { // process echo $cat, '<br/>'; } Link to comment Share on other sites More sharing options...
mkr365 Posted April 8, 2008 Author Share Posted April 8, 2008 Sorry for asking, but do i have to insert the next code: foreach ($_POST['catogorien'] as $cat { // process echo $cat, '<br/>'; } Or do i only have to change name="categorien" to name="categorien[]" ? (this last thing isn't working) Link to comment Share on other sites More sharing options...
fenway Posted April 8, 2008 Share Posted April 8, 2008 Sorry for asking, but do i have to insert the next code: foreach ($_POST['catogorien'] as $cat { // process echo $cat, '<br/>'; } Or do i only have to change name="categorien" to name="categorien[]" ? (this last thing isn't working) Did you try both? Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 To get all selected values posted you need the [] adding. The other code was just an example of processing the POST data, showing that all selcted values are now there Link to comment Share on other sites More sharing options...
mkr365 Posted April 10, 2008 Author Share Posted April 10, 2008 Well if i change it to name="categorien[]" i get the following error: Unknown column 'Array' in 'where clause' code: <tr><td>Rubriek:</td><td>'; $sql = "SELECT * FROM rubrieken INNER JOIN groepen ON rubrieken.GroepID = groepen.GroepID WHERE Groepnaam = 'Architect' ORDER BY Rubrieknaam "; $result = mysql_query($sql) or die(mysql_error()); while($query = mysql_fetch_array($result)) { if ($_GET['categorien'] == $query['RubriekID']) echo '<input type="checkbox" name="categorien[]" value="'.$query['RubriekID'].'" checked>'.$query['Rubrieknaam'].''; else echo '<input type="checkbox" name="categorien[]" value="'.$query['RubriekID'].'">'.$query['Rubrieknaam'].''; } echo '</select></td></tr> <tr><td colspan="2"><input type="submit" value="zoeken"><input type="hidden" name="zoek" value="true"></td></tr> Link to comment Share on other sites More sharing options...
fenway Posted April 10, 2008 Share Posted April 10, 2008 Not in the where clause you posted...?!? Link to comment Share on other sites More sharing options...
mkr365 Posted April 11, 2008 Author Share Posted April 11, 2008 You mean there something wrong with the where clause? <tr><td>Rubriek:</td><td>'; $sql = "SELECT * FROM rubrieken INNER JOIN groepen ON rubrieken.GroepID = groepen.GroepID WHERE Groepnaam = 'Architect' ORDER BY Rubrieknaam "; Link to comment Share on other sites More sharing options...
fenway Posted April 11, 2008 Share Posted April 11, 2008 Where does this error -- "Unknown column 'Array' in 'where clause' " -- come from? Which line? Link to comment Share on other sites More sharing options...
mkr365 Posted April 11, 2008 Author Share Posted April 11, 2008 Hello, Well i have several errors: Undefined index: bedrijfsnaam in C:\\webroot\\Nieuw Bouwref\\headerarchitect.php on line 232 Undefined index: categorien in C:\\webroot\\Nieuw Bouwref\\headerarchitect.php on line 241 line 232 : <tr><td>Bedrijfsnaam:</td><td><input type="text" name="bedrijfsnaam" value="'.$_GET['bedrijfsnaam'].'"input SIZE="30"></td></tr> line 241: if ($_GET['categorien'] == $query['RubriekID']) Seems like "bedrijfsnaam" and "categorien" are unknown. Link to comment Share on other sites More sharing options...
fenway Posted April 11, 2008 Share Posted April 11, 2008 "Undefined index" sounds like a php error.... Link to comment Share on other sites More sharing options...
mkr365 Posted April 11, 2008 Author Share Posted April 11, 2008 I think it is, i will post it in the php forum. Very thanks for your help! Link to comment Share on other sites More sharing options...
Recommended Posts