usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 lol yeah thats everything, ready to start editing the index. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338432 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 Just to make sure u know that currently i have a index.html and have another file named insert.php that executes the code in the index.html page. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338437 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2012 Share Posted April 18, 2012 ok, make a copy of index.html and name it something along the lines of idx.php, this will give us a safe area to work in.  Once that's done have a look at these code snipits <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){  if ($minRooms == 0){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minRooms\">$minRooms</option>";  } } ?> </select> ?> <select name="min price" ...> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice+10){  if ($minPrice == 40){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minPrice\">£$minRooms</option>";  } } ?> </select> They are going to generate your dropdowns for price and bedrooms. I've included the start of each <select> so you can see exactly where they will go. you'll need to add in copy's for the max versions as well, just make sure and change the min to max, you don't need to re-declare the $xxxLimit as it's going to be the same and isn't changed in the loops. Doing it this way makes the source of the page you see is shorter and easier to maintain. so if in the future you want to add a property that's 600k, or a house with 8 bedrooms, you don't need to add all those lines manualy to keep continuity, just change a number and your done. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338439 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 Sorry where abouts in the html file am i pasting that code? Â heres the HTML for number of bedrooms: Â <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <select name="min bedrooms"> <option value="none" selected="selected">No Min</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> to <select name="max bedrooms"> <option value="none" selected="selected">No Max</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> </td> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338454 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2012 Share Posted April 18, 2012 ok, revised code, buggered the loop on the price select. <select name="min bedrooms"> <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){  if ($minRooms == 0){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minRooms\">$minRooms</option>";  } } ?> </select> <select name="min price"> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){  if ($minPrice == 40){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minPrice\">£$minPrice</option>";  } } ?> </select> The code replaces all the html between the opening and closing <select> so: <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <select name="min bedrooms"> <?php // ***IN HERE***    ?> </select> to Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338461 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 Is this right for the minimum and maximum bedrooms: Â <select name="min bedrooms"> <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){ Â if ($minRooms == 0){ Â Â echo"<option value=\"0\" selected=\"selected\">No Min</option>"; Â } Â else{ Â Â echo "<option value\"$minRooms\">$minRooms</option>"; Â } } ?> </select> to <select name="max bedrooms"> <?php $roomLimit = 5; for($maxRooms = 0; $maxRooms <= $roomLimit; $maxRooms++){ Â if ($maxRooms == 0){ Â Â echo"<option value=\"0\" selected=\"selected\">No Max</option>"; Â } Â else{ Â Â echo "<option value\"$maxRooms\">$maxRooms</option>"; Â } } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338469 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 and done for the minimum and maximum price range:  <td><p class="PR">Price range:</p></td> <td><div id="PR"> <select name="min price"> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice+10){  if ($minPrice == 40){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minPrice\">£$minRooms</option>";  } } ?> </select> to <select name="max price"> <?php $priceLimit = 350; for($maxPrice = 40; $maxPrice <= $priceLimit; $maxPrice+10){  if ($maxPrice == 40){   echo"<option value=\"0\" selected=\"selected\">No Max</option>";  }  else{   echo "<option value\"$maxPrice\">£$maxRooms</option>";  } } ?> </select> </div> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338471 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2012 Share Posted April 18, 2012 looks good, what do you see if you go to your idx.php (or whatever you called it)? Â Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338473 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 check the link here: http://mumtazproperties.hostei.com/ Â basically the bedrooms is working but the price range is not, plus the rest of the bottom of my page has been cut off. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338477 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2012 Share Posted April 18, 2012 yeah, sorry, that's the screwed up loop version of the code you'll need to change to this: <select name="min price"> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){  if ($minPrice == 40){   echo"<option value=\"0\" selected=\"selected\">No Min</option>";  }  else{   echo "<option value\"$minPrice\">£$minPrice</option>";  } } ?> </select> The rest of the page should render after that, the problem is that the screwed up version runns an infinate loop, so the page gets jammed there. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338480 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 Thats brilliant, yeah thats working now. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338482 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2012 Share Posted April 18, 2012 Well I'm off for the night, but I'll leave you some stuff to have a play with:  first up, make a new file and call it "mstr_ref.inc". in it have the following code (changing the credentials to your own): <?php define('__HOST', 'localhost'); //localhost = database host name (normaly this won't need changing) define('__USER', 'xxx');  //xxx = database username define('__PASS', 'xxx');  //xxx = database password define('__DEF_DB', 'xxx'); //xxx = database name $con = mysql_connect(__HOST, __USER, __PASS) or die(mysql_error()); $db = mysql_select_db(__DEF_DB, $con) or die (mysql_error()); ?>  then add this code to the top of the idx.php: <?php require_once 'mstr_ref.inc'; ?>  this now meens that the idx.php can connect to the database. which is good, because next we want to use the following piece of code to create the locations element for the form. This way each time a new location gets added to the database it will show in the list without any other action needed.  using what you've picked up from the bedrooms and prices you should be able to insert this bit of code to get the locations displaying out of the database (remember you will need to have them in the database first of all)  Note: the <select> is being echoed from within the code this time, so watch out for that. <?php $locationSql = "SELECT id, area_name FROM Locations GROUP by area_name"; $locQry = mysql_query($locationSql) or die (mysql_error()); echo "<select name=\"areas\" multiple=\"multiple\" size\"=5\" style=\"width:150px;\">"; while ($location = mysql_fetch_assoc($locQry)){ echo "<option value=\"{$location['id']}\">{$location['area_name']}</option>"; } echo "</select>"; ?>  also, we'll use the catagories table for storing the types "house" and "flat" in, so you can use the type column for semi, bungalow etc. have a shot scripting the Property Type <select> box to read from the catagories table and display the results. Everything you need is in the code here, so it should be easy enough.  I'll check back in in the morning and work on scripting up some more stuff. Good Luck  Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338483 Share on other sites More sharing options...
usman07 Posted April 18, 2012 Author Share Posted April 18, 2012 thanks so much, uv helped me a tremendous lot! no words can thank you enough! Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338491 Share on other sites More sharing options...
Muddy_Funster Posted April 19, 2012 Share Posted April 19, 2012 so how did you get on with that code? Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338672 Share on other sites More sharing options...
usman07 Posted April 19, 2012 Author Share Posted April 19, 2012 Alryt mate, i actually got stuck. for some reason it won't connect to the database? I followed what u said about create a new file called "mstr_ref.inc" and pasted that code that u provided and inserted my own credentials. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1338889 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2012 Share Posted April 20, 2012 ok, let's see the code you have now as well as any error messages. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339001 Share on other sites More sharing options...
usman07 Posted April 20, 2012 Author Share Posted April 20, 2012 ok thanks. Â heres the code in the mstr_ref.inc file <?php define('__HOST', ''); //localhost = database host name (normaly this won't need changing) define('__USER', '');Â Â //xxx = database username define('__PASS', '');Â Â //xxx = database password define('__DEF_DB', ''); //xxx = database name $con = mysql_connect(__HOST, __USER, __PASS) or die(mysql_error()); $db = mysql_select_db(__DEF_DB, $con) or die (mysql_error()); ?> Â and Iv put the code as you said at the top in my index.php file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php require_once 'mstr_ref.inc'; ?> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Mumtaz Properties</title> <link rel="stylesheet" href="cutouts/style.css"/> </head> <body> Â And then when i view this and press the submit button on the form it displays everything that it written in the mstr_ref.inc file like this: <?php define('__HOST', ''); //localhost = database host name (normaly this won't need changing) define('__USER', '');Â Â //xxx = database username define('__PASS', '');Â Â //xxx = database password define('__DEF_DB', ''); //xxx = database name $con = mysql_connect(__HOST, __USER, __PASS) or die(mysql_error()); $db = mysql_select_db(__DEF_DB, $con) or die (mysql_error()); ?> Â Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339039 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2012 Share Posted April 20, 2012 then the most likely probem is your hosing isn't configured to parse .inc files as php files. change the extension to . php and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339138 Share on other sites More sharing options...
usman07 Posted April 20, 2012 Author Share Posted April 20, 2012 ok i did that, now I get a error 404 Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339142 Share on other sites More sharing options...
usman07 Posted April 20, 2012 Author Share Posted April 20, 2012 Where should I place the code in my index.php to link the mstr_ref.php file? heres where it is at the moment <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Mumtaz Properties</title> <link rel="stylesheet" href="cutouts/style.css"/> <?php require_once 'mstr_ref.php'; ?> </head> <body> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339145 Share on other sites More sharing options...
usman07 Posted April 21, 2012 Author Share Posted April 21, 2012 Ok it was my fault, i needed to change the form action like this: <form action="mstr_ref.php" method="get"> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339296 Share on other sites More sharing options...
usman07 Posted April 21, 2012 Author Share Posted April 21, 2012 Do i place this code in the mstr_ref.php file or in my index.php file where my form is? thanks <?php $locationSql = "SELECT id, area_name FROM Locations GROUP by area_name"; $locQry = mysql_query($locationSql) or die (mysql_error()); echo "<select name=\"areas\" multiple=\"multiple\" size\"=5\" style=\"width:150px;\">"; while ($location = mysql_fetch_assoc($locQry)){ echo "<option value=\"{$location['id']}\">{$location['area_name']}</option>"; } echo "</select>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339300 Share on other sites More sharing options...
Muddy_Funster Posted April 22, 2012 Share Posted April 22, 2012 your form action should still point to where it always did, you're not posting the form to the mstr_ref.php, it's just a file that we are going to reqire_once on each page (and as PHP code as all parsed befor the page reaches the browser, it doesn't really matter where on the page it goes (normaly, there are some exceptions). mstr_ref.php holds the info in it that is of common use, such as database connection. Do i place this code in the mstr_ref.php file or in my index.php file where my form is? thanks <?php $locationSql = "SELECT id, area_name FROM Locations GROUP by area_name"; $locQry = mysql_query($locationSql) or die (mysql_error()); echo "<select name=\"areas\" multiple=\"multiple\" size\"=5\" style=\"width:150px;\">"; while ($location = mysql_fetch_assoc($locQry)){ echo "<option value=\"{$location['id']}\">{$location['area_name']}</option>"; } echo "</select>"; ?> You put that code in the index.php file, to replace the html code that is making the current <select name="areas">. None of the code is going off page yet, so clicking the submit button isn't going to do anything new (at least it shouldn't) We still want to have the form point to the page that will be displaying the results.  so just now you should have 3 pages : index.php has a form that links to insert.php and mstr_ref.php that is currently used in index.php vie a require_once call. the form still points -> to insert.php, but as we havn't looked at that page yet, there isn't anything much going to happen when you submit the form. although I on't think that's really the best name for the page that we want the form to go to as we're not doing anthing that reales to "insert", so once we have the index page sorted out well look at making a new page calling it results.php Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339553 Share on other sites More sharing options...
usman07 Posted April 22, 2012 Author Share Posted April 22, 2012 ahh right ok, so il change it back to what it was cuz it was pointing towards my insert.php file which is the php i previously had that displayed my 'properties' table <form action="insert.php" method="get"> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339574 Share on other sites More sharing options...
usman07 Posted April 22, 2012 Author Share Posted April 22, 2012 do i place the PHP code for the location like this in the index.php file? thanks. <td><p class="LOC">Location:</p></td> <td><div id="LC"> <select multiple="multiple" name="area" size="5" style="width: 150px;" > <option>Armley</option> <option>Chapel Allerton</option> <option>Harehills</option> <option>Headingley</option> <option>Hyde Park</option> <option>Moortown</option> <option>Roundhay</option> <?php $locationSql = "SELECT id, area_name FROM Locations GROUP by area_name"; $locQry = mysql_query($locationSql) or die (mysql_error()); echo "<select name=\"areas\" multiple=\"multiple\" size\"=5\" style=\"width:150px;\">"; while ($location = mysql_fetch_assoc($locQry)){ echo "<option value=\"{$location['id']}\">{$location['area_name']}</option>"; } echo "</select>"; ?> </select> </div> Quote Link to comment https://forums.phpfreaks.com/topic/261048-php-search-form/page/2/#findComment-1339583 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.