simun Posted July 8, 2009 Share Posted July 8, 2009 helo i have 3 checkboses that send vaule to sql query by variable $val <? $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { echo "$val"; echo "<form method=post action=''>"; echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' > <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=box[] value='AND interijer = 1 '></td> <td width='25%'> Interijer</td> <td width='25%'><input type=checkbox name=box[] value='AND detalji = 1 '></td> <td width='25%'> Detalji</td> <td width='25%'><input type=checkbox name=box[] value='AND ostalo = 1 '></td> <td width='25%'> Ostalo</td> <td colspan =6 align=center><input type=submit value=Filtriraj></form></td></tr> </table>"; ?> here is my query: $sql .= '' . $val . ' ORDER BY id DESC';} now when i select onley one checkbox it work fine, but when i select 2 or 3 it don t show nothing, i have try to echo variable $val and it work fine too but dont send to query 2 or 3 values from check boxes. please some help? here is the whole .php page <?php $sql = 'SELECT * FROM objects WHERE zupanija = "obiteljske"'; if (! empty($__current['database']['query'])) { $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { echo "$val"; $sql .= '' . $val . ' ORDER BY id DESC';} } if (isset($__current['database']['per_page'])) { $result_total = mysql_query($sql); if ($result_total) { $total_objects = mysql_num_rows($result_total); mysql_free_result($result_total); } $total_pages = ceil((int)$total_objects / (int)$__current['database']['per_page']); if (isset($_GET['l'])) { $limit = $_GET['l']; } $sql .= ' LIMIT ' . (int)$limit . ', ' . (int)$__current['database']['per_page']; } if ((int)$__query[3] > 0) { $object = new S_Object; if ($object->load((int)$__query[3])) { $__current['title'][$__language] = $object->{'naziv_' . $__language} . ' - ' . $__current['title'][$__language]; include('object_galerija.details.php'); } } else { $query = mysql_query($sql); include('templates/' . $__config['template'] . '/header.php'); include('templates/' . $__config['template'] . '/menu2.php'); ?> <div id="content"> <div style="float:left"> <h1><?=$__current["title"][$__language]?></h1> </div> <div style="float:right; padding-top:10px;"> <p> <form action="../"> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="">Sortiraj po...</option> <option value="<?php echo '/' . $__language . '/galerija'?>">Sve</option> <option value="<?php echo '/' . $__language . '/galerija_obi'?>">Obiteljske</option> <option value="<?php echo '/' . $__language . '/galerija_sta'?>">Stambene</option> <option value="<?php echo '/' . $__language . '/galerija_vis'?>">Visestambene</option> <option value="<?php echo '/' . $__language . '/galerija_pos'?>">Poslovne</option> <option value="<?php echo '/' . $__language . '/galerija_sak'?>">Sakralne</option> <option value="<?php echo '/' . $__language . '/galerija_stu'?>">Urb/Arh studije</option> </select> </form> <? echo "<form method=post action=''>"; echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' > <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=box[] value='AND interijer = 1 '></td> <td width='25%'> Interijer</td> <td width='25%'><input type=checkbox name=box[] value='AND detalji = 1 '></td> <td width='25%'> Detalji</td> <td colspan =6 align=center><input type=submit value=Filtriraj></form></td></tr> </table>"; ?> </p> </div> <?php echo '<!--' . $sql . '-->'; //************************************************************************ // PAGER //************************************************************************ if ($total_pages > 1) { ?> <div class="pager"> <?php $page_next = $limit + $__current['database']['per_page']; $page_next_limit_string = '/?l=' . $page_next; $page_prev = $limit - $__current['database']['per_page']; $page_prev_limit_string = '/?l=' . $page_prev; if ((int)$page_prev == 0) { $page_prev_limit_string = ''; } if ($page_prev > -1) { ?> <a href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_prev_limit_string ?>" class="arrow"><<</a> <?php } for ($p = 1; $p <= $total_pages; $p++) { $page_limit = ($p-1)*$__current['database']['per_page']; $page_limit_string = '/?l=' . (int)$page_limit; if ($page_limit == 0) { $page_limit_string = ''; } ?> <a<?php if ($limit == $page_limit) echo ' class="selected"'; ?> href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_limit_string ?>"><?=$p?></a> <?php } if ($page_next < $total_objects) { ?> <a href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_next_limit_string ?>" class="arrow">>></a> <?php } ?> </div> <div class="clear"></div> <?php } //************************************************************************ if ($query) { $counter = 0; while ($o = mysql_fetch_assoc($query)) { include('object_galerija.small.php'); $counter++; } } //************************************************************************ // PAGER //************************************************************************ if ($total_pages > 1) { ?> <div class="clear"></div> <div class="pager"> <?php $page_next = $limit + $__current['database']['per_page']; $page_next_limit_string = '/?l=' . $page_next; $page_prev = $limit - $__current['database']['per_page']; $page_prev_limit_string = '/?l=' . $page_prev; if ((int)$page_prev == 0) { $page_prev_limit_string = ''; } if ($page_prev > -1) { ?> <a href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_prev_limit_string ?>" class="arrow"><<</a> <?php } for ($p = 1; $p <= $total_pages; $p++) { $page_limit = ($p-1)*$__current['database']['per_page']; $page_limit_string = '/?l=' . (int)$page_limit; if ((int)$page_limit == 0) { $page_limit_string = ''; } ?> <a<?php if ($limit == $page_limit) echo ' class="selected"'; ?> href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_limit_string ?>"><?=$p?></a> <?php } if ($page_next < $total_objects) { ?> <a href="<?php echo '/' . $__language . '/' . $__current['link'][$__language] . $page_next_limit_string ?>" class="arrow">>></a> <?php } ?> </div> <?php } //************************************************************************ ?> </div> <? include('templates/' . $__config['template'] . '/footer.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/ Share on other sites More sharing options...
ignace Posted July 8, 2009 Share Posted July 8, 2009 Your query is wrong you'll get: SELECT * FROM objects WHERE zupanija = "obiteljske"{$val} ORDER BY id DESC{$val} ORDER BY id DESC{$val} ORDER BY id DESC{$val} ORDER BY id DESC while this should be: SELECT * FROM objects WHERE zupanija = "obiteljske" AND column(n)={$val(n)} AND column(n+1)={$val(n+1)} .. ORDER BY id DESC Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/#findComment-870856 Share on other sites More sharing options...
simun Posted July 8, 2009 Author Share Posted July 8, 2009 oh, now i see the problem, thanks you my man Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/#findComment-870859 Share on other sites More sharing options...
simun Posted July 8, 2009 Author Share Posted July 8, 2009 oh, now i see the problem, thanks you my man But my query is sperate, $sql = 'SELECT * FROM objects WHERE zupanija = "obiteljske"'; if (! empty($__current['database']['query'])) { $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { echo "$val"; $sql .= '' . $val . ' ORDER BY id DESC';} } how will i order my data if i remove ORDER BY id DESC? where to put order by? Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/#findComment-870861 Share on other sites More sharing options...
simun Posted July 8, 2009 Author Share Posted July 8, 2009 now work fine and look like this $sql = 'SELECT * FROM objects WHERE zupanija = "obiteljske"'; $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { $sql .= '' . $val . '';} how can i order data now??? Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/#findComment-870872 Share on other sites More sharing options...
sasa Posted July 8, 2009 Share Posted July 8, 2009 $sql = 'SELECT * FROM objects WHERE zupanija = "obiteljske"'; $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { $sql .= '' . $val . '';} $sql .= ' ORDER BY id DESC'; add order by outside while loop Quote Link to comment https://forums.phpfreaks.com/topic/165161-mysql-query-by-checkboxes/#findComment-870884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.