Jump to content

Adib

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

Adib's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've tried your last script but didn't work I use this script and everything works fine except when i select something for $prijsVanOptions and $prijsTotOptions this script shows the result of $prijsTotOption. It has to show the result between $prijsVanOptions and $prijsTotOptions. <?php // Search.php include ('config.php'); //Function to generate select options from a query function querySelectOptions($query) { //Create default option $optionsHTML = "<option value=''>-----</option>\n"; //Run query $result = mysql_query ($query); if(!$result) { return $optionsHTML; } //Process results while($row = mysql_fetch_array($result)) { $optionsHTML .= "<option value='{$row[1]}'>{$row[1]}</option>\n"; } return $optionsHTML; } //Create locatie options $locatieOptions = querySelectOptions("SELECT ID, locatie FROM locatie"); //Create prijsVan options $prijsVanOptions = querySelectOptions("SELECT ID, prijs FROM prijs where prijs >= prijs"); //Create prijsTot options $prijsTotOptions = querySelectOptions("SELECT ID, prijs FROM prijs where prijs <= prijs"); //Create ligging options $liggingOptions = querySelectOptions("SELECT ID, ligging FROM ligging"); //Create oppervlakte options $oppervlakteOptions = querySelectOptions("SELECT ID, oppervlakte from oppervlakte"); //Create kamers options $kamersOptions = querySelectOptions("SELECT ID, kamers from kamers"); //Create woning options $woningOptions = querySelectOptions("SELECT ID, type from woning"); ?> <select name="condition[locatie]" id="locatie"> <?php echo $locatieOptions; ?> </select><br> <select name="condition[prijs]" id="prijs"> <?php echo $prijsVanOptions; ?> </select><br> <select name="condition[prijs]" id="prijs"> <?php echo $prijsTotOptions; ?> </select><br> <select name="condition[ligging]" id="ligging"> <?php echo $liggingOptions; ?> </select><br> <select name="condition[oppervlakte]" id="oppervlakte"> <?php echo $oppervlakteOptions; ?> </select><br> <select name="condition[kamers]" id="kamers"> <?php echo $kamersOptions; ?> </select><br> <select name="condition[type]" id="type"> <?php echo $woningOptions; ?> </select><br> <input type="submit" name="submit" value="Zoeken"> <?php //Result.php require_once ('config.php'); function postError(){ print '<br><br><p> <h1>Je hebt geen keuze gemaakt!</h1>'; print '<h2>Maak een keuze!</h2>'; } $query = "SELECT DISTINCT * FROM huur, prijs, locatie, ligging, kamers, woning, oppervlakte, eigenschappen where huur.prijs_id = prijs.ID AND huur.locatie_id = locatie.ID AND huur.ligging_id = ligging.ID AND huur.kamers_id = kamers.ID AND huur.type_id = woning.ID AND huur.oppervlakte_id = oppervlakte.ID AND huur.eigenschappen_id = eigenschappen.ID "; function processConditions($postConditions) { $conditionsAry = array(); foreach($postConditions as $field => $value) { $value = trim($value); if(!empty($value)) { $value = mysql_real_escape_string($value); $conditionsAry[] = "`{$field}` = '{$value}'"; } } return $conditionsAry; } //Process the conditions that were posted $conditionsArray = processConditions($_POST['condition']); // Error: indien geen keuze gemaakt show deze error if(count($conditionsArray)==0) { echo "<center><font color='#666'> " . postError() . "</font></center>\n"; } else { //Create / Execute query $query .= " AND " . implode(' AND ', processConditions($_POST['condition'])); $query .= " ORDER BY prijs.ID"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['image_id']; echo $row['locatie']; echo $row['prijs']; echo $row['type']; echo $row['kamers']; echo $row['oppervlakte'] . ' m&#178;'; echo $row['ligging']; echo $row['eigenschappen']; } } ?>
  2. Thanx again for this great solution. Here i need for the last time your help. Ass you see i have two select boxes where i can select the price: 1. prijsVan. This means price from. 2. prijsTot. This means price to. I have one table for the prices with column names ID as primary key(auto_increment) and prijs for the amount of price(e. 50000) How to make this combination possible. imagine i choose 50000 as prijsVan and 100000 as prijsTot. The script then should show the result of the price between 50000 and 100000 and if i only select something from one of these select boxes then the script should show only the prices from the chosen option. This will be the last thing i ask Appreciate your help
  3. Thanx this works like a charm. But now I have an other problem. In the selectbox for: <select name="condition[prijsVan]" id="prijsVan"> <?php echo $prijsVanOptions; ?> </select> I want to add the euro sign. How do i do that?
  4. Use single quote like this: echo '<a href="whatever">link_name</a>';
  5. Hi, I'm using a form which contains many select boxes. The select boxes looks like this: <select name="locatie" id="locatie"> <option value="" selected>-----</option> <?php require_once ('config.php'); $query = "select ID, locatie from locatie"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$locatie.'</option>'; } ?> </select> <select name="prijsVan" id="prijsVan"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="prijsTot" id="prijsTot"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="ligging" id="ligging"> <option value="" selected>-----</option> <?php $query = "select ID, ligging from ligging"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$ligging.'</option>'; } ?> </select> <select name="oppervlakte" id="oppervlakte"> <option value="" selected>-----</option> <?php $query = "select ID, oppervlakte from oppervlakte"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$oppervlakte.' m&#178;</option>'; } ?> </select> <select name="kamers" id="kamers"> <option value="" selected>-----</option> <?php $query = "select ID, kamers from kamers"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$kamers.'</option>'; } ?> </select> <select name="woning" id="woning"> <option value="" selected>-----</option> <?php $query = "select ID, type from woning"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$type.'</option>'; } ?> </select> <input type="submit" name="submit" value="Zoeken"> To display the result i'm using a PHP processing page which contains the flowing code: <?php ...... ..... $locatie = $_POST['locatie']; $prijsVan = $_POST['prijsVan']; $prijsTot = $_POST['prijsTot']; $ligging = $_POST['ligging']; $oppervlakte = $_POST['oppervlakte']; $kamers = $_POST['kamers']; $woning = $_POST['woning']; $eigenschappen = $_POST['eigenschappen']; // SHOW LOCATIE if($locatie !='' && $prijsVan =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie. "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSVAN if($prijsVan !='' && $locatie !='' && $prijsTot =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSTOT if($prijsTot !='' && $locatie !='' && $prijsVan =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS VAN if($prijsVan !='' && $locatie =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW PRIJS TOT if($prijsTot !='' && $locatie =='' && $prijsVan =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS_VAN_PRIJS_TOT if($prijsVan !='' && $prijsTot !='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND prijs.ID BETWEEN '" . $prijsVan . "' AND '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW LIGGING if($ligging !='' && $prijsVan =='' && $prijsTot =='' && $locatie =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND ligging.ID = '" . $ligging. "' ORDER BY prijs.ID"; } ...................... and so on......... // Error: indien geen keuze gemaakt show deze error if($prijsVan =='' && $prijsTot =='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { ?> <center><font color="#666"> <?php postError(); ?></font></center><?php } else{ //Execute query $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['image_id'] ; echo $row['locatie'] ; echo $row['prijs']; echo $row['type']; echo $row['kamers']; echo $row['oppervlakte'] . ' m&#178;'; echo $row['ligging']; echo $row['eigenschappen']; } } mysql_close($con); ?> As you see i have to use many IF condition to display the result of every select combinations. Is there any way to do it in better way and using less coding? Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.