Jump to content

oblivion2010

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by oblivion2010

  1. Hey guys, pretty new to PHP, and I'm trying to create a dog search engine. I'm trying to use checkboxes, and radio buttons on a form, with the results showing a list of dogs that match the users critera. The code I'm using on the results.php page are below. <?php $host="localhost"; $username="********"; $pass="*******"; mysql_connect($host,$username,$pass); mysql_select_db($username); if(isset($_POST['shelters'])){ $breeds_where = ""; if(isset($_POST['breeds'])){ foreach($_POST['breeds'] as $breed){ $breed = mysql_real_escape_string($breed); if($breeds_where != ""){ $breeds_where .= " OR "; } $breeds_where .= "`breed_id` = $breed"; } echo "<h3>$breed </h3><br/>"; } $common_where = ""; if(isset($_POST['sex'])){ if($_POST['sex'] == "male"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`male` = 1"; }elseif($_POST['sex'] == "female"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`male` = 0"; } } if(isset($_POST['child'])){ if($_POST['child'] == "yes"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`child` = 1"; } } if(isset($_POST['dogs'])){ if($_POST['dogs'] == "yes"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`other_dogs` = 1"; }elseif($_POST['dogs'] == "no"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`other_dogs` = 0"; } } if($breeds_where != ""){ if($common_where != ""){ $common_where .= " AND "; } $common_where .= "($breeds_where)"; } foreach($_POST['shelters'] as $shelter){ echo "<h2>$shelter</h2><br />"; $shelter = mysql_real_escape_string($shelter); $query = "SELECT * FROM `dogs` WHERE `shelters_id` = $shelter AND $common_where"; $result = mysql_query($query) or die(mysql_error() . "<br>" . $query); if(mysql_num_rows($result) == 0){ echo "No matching dogs<br />"; continue; } while($row = mysql_fetch_assoc($result)){ $breed = mysql_result(mydsql_query("SELECT `breedname` FROM `breeds` WHERE `id` = {$row['breed_id']}")or die(mysql_error()),0); echo "<h3>$breed </h3><br/>"; echo ($row['male'] == 1?"Male":"Female"). "<br />"; echo ($row['child'] == 1?"Good For Children":"Not so good with Children"). "<br />"; echo ($row['other_dogs'] == 1?"Good with other dogs":"Not so good with other dogs"). "<br />"; } } } ?> This code is only showing me the ID numbers of the last selected breed / shelter's. See here: http://hermes.hud.ac.uk/u0656983/Dog%20Website/ Any idea's how I can rectify this code, or is there a better way to go about doing a search engine using a form? Thanks for any help.
  2. Doesn't make much sense, maybe I should just strat from scratch, new database, new PHP. Getting late on this side of the world, so I'll be back tommorow, thanks for all your help. Much appreciated.
  3. Yeah, I'm updating the code with every update you're posting. The only output that is being displayed is the ID of the last breed that is checked. Strange.
  4. Afraid not, more of the same. Why is it displaying Array ( [shelters] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 7 ) [breeds] => Array ( [0] => 5 [1] => 6 ) [sex] => Male [child] => No [dogs] => No [submit] => Submit ) At the top of the results page?
  5. Ahh, it is now giving me results, but it's only giving me the ID for the Breed and the Shelter. Check it out: http://hermes.hud.ac.uk/u0656983/Dog%20Website/
  6. I only have two pages, an Index.php (2nd post) and a results.php page (1st post) I've attached both. (Had to call the Index page a different name due to restrictions on the forum) [attachment deleted by admin]
  7. Sure mate. <!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>Untitled Document</title> </head> <body> <?php $host="localhost"; $username="******"; $pass="******"; mysql_connect($host,$username,$pass); mysql_select_db($username); $result = mysql_query("SELECT * FROM `shelters`"); while($row = mysql_fetch_assoc($result)){ echo "<input type=\"checkbox\" name=\"shelters[]\" id=\"shelters_{$row['id']}\" value=\"{$row['id']}\" /><label for=\"shelters_{$row['id']}\">{$row['sheltername']}</label><br/>"; } $result = mysql_query("SELECT * FROM `breeds`"); while($row = mysql_fetch_assoc($result)){ echo "<input type=\"checkbox\" name=\"breeds[]\" id=\"breeds_{$row['id']}\" value=\"{$row['id']}\" /><label for=\"breeds_{$row['id']}\">{$row['breedname']}</label><br/>"; } ?> <h2 class="title">Gender</h2> <p class="sub">Indicate if you would prefer a male of female</p> <form method="post" action="results.php"> <label for="male">Male</label> <input type="radio" name="sex" id="male" value="Male" /> <label for="female"> Female <input type="radio" name="sex" id="female" value="Female" /> </label> <label for="both">Don't Mind</label> <input name="sex" type="radio" id="both" value="both" checked="checked" /> <h2 class="title">Child Friendly?</h2> <p class="sub">Will your dog be living around young children?</p> <input name="child" type="radio" id="yes" value="Yes" checked="checked" /> <label for="yes">Yes</label> <input type="radio" name="child" id="no" value="No" /> <label for="no">No</label> <h2 class="title">Living with other dogs?</h2> <p class="sub">Will your dog be living with any other dogs?</p> <input name="dogs" type="radio" id="yes" value="Yes" checked="checked" /> <label for="yes">Yes</label> <input type="radio" name="dogs" id="no" value="No" /> <label for="no">No</label> <p> <input type="submit" name="submit" id="submit" value="Submit" /> </body> </html>
  8. I used the code, and still the same blank page appeared. I then entered 'print_r($_POST);' at the top of the code, and it displayed. Array ( [sex] => Male [child] => Yes [dogs] => Yes [submit] => Submit )
  9. Cheers ratcateme for your help. I've been playing with your code for a while, to no avail. When I click submit, it takes me to the results page with no error, but it's just a blank page. I've editted all of your names to match the names in my database, any idea where I just get a blank white screen? <?php $host="localhost"; $username="******"; $pass="******"; mysql_connect($host,$username,$pass); mysql_select_db($username); if(isset($_POST['shelters'])){ $breeds_where = ""; if(isset($_POST['breeds'])){ foreach($_POST['breeds'] as $breed){ $breed = mysql_real_escape_string($breed); if($breeds_where != ""){ $breeds_where .= " OR "; } $breeds_where .= "`breed_id` = $breed"; } } $common_where = ""; if($_POST['sex'] == "male"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`male` = 1"; }elseif($_POST['sex'] == "female"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`male` = 0"; } if($_POST['child'] == "yes"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`child` = 1"; } if($_POST['dogs'] == "yes"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`other_dogs` = 1"; }elseif($_POST['dogs'] == "no"){ if($common_where != ""){ $common_where .= " AND "; } $common_where = "`other_dogs` = 0"; } if($breeds_where != ""){ if($common_where != ""){ $common_where .= " AND "; } $common_where .= "($breeds_where)"; } foreach($_POST['shelters'] as $shelter){ echo "<h2>$shelter</h2><br />"; $shelter = mysql_real_escape_string($shelter); $query = "SELECT * FROM `dogs` WHERE `shelters_id` = $shelter AND $common_where"; $result = mysql_query($query) or die(mysql_error() . "<br>" . $query); if(mysql_num_rows($result) == 0){ echo "No matching dogs<br />"; continue; } while($row = mysql_fetch_assoc($result)){ $breed = mysql_result(mydsql_query("SELECT `breedname` FROM `breeds` WHERE `id` = {$row['id']}")or die(mysql_error()),0); echo "<h3>$breed </h3><br/>"; echo ($row['male'] == 1?"Male":"Female"). "<br />"; echo ($row['child'] == 1?"Good For Children":"Not so good with Children"). "<br />"; echo ($row['other_dogs'] == 1?"Good with other dogs":"Not so good with other dogs"). "<br />"; } } } ?>
  10. $sql .= " AND ( 0=1 "; /* to make adding 'OR' conditions easy */ $temp = ""; foreach ($_POST['breed'] as $chosen_breed_id) { $temp = " OR dogs.breedid = '".$chosen_breed_id ."' \n " } The last line is line 41.
  11. Wow, thanks Dave! I appreciate your effort, however I'm getting a parse error: 'Parse error: parse error, unexpected '}' in /spare/apache2/htdocs/stud/u0656983/Dog Website/results.php on line 49' I can't understand why it claims it's unexpected, any ideas?
  12. Thanks for the replies. I already have a Dog ID and Shelter ID in my dogs table. My problem is not having the knowledge to link up the checkboxes to the database. I have my varibles checking to see which checkboxes are selected: $chosenShelters=$_POST["shelter"]; $chosenBreeds=$_POST["breed"]; and then I have the PHP coding $query= "SELECT * WHERE dogs.shelter=shelters.shelterid AND table.dog_id=breeds.dog_breed" $result=mysql_query($query); $row = mysql_fetch_array($result); foreach($chosenShelters as $chosenShelter){ echo $row['dog_name']."<br />"; } mysql_close(); This code is attemping to show the name of the dog which has the same shelter ID and dog ID as the user selected. Though I don't know how to link the two pieces of code up. Thanks again for the help.
  13. Hi, I'm attempting to create a Dog Rehoming website. The user needs to select their preferred Breed of dog and location of shelter. They will select these prefrecnes via checkboxes. The website I'm working on: http://hermes.hud.ac.uk/u0656983/Dog%20Search/Dog%20Website/ On my database I have three tables, Dogs, Breeds, and Shelters. I want my Results.php page to show a list of dogs that match the users Breed and Shelter prefrences, whats the best way to do this? I've also attached the two php file I'm using, thanks for any help. [attachment deleted by admin]
  14. Thanks Scott, I've been working on my Database via MySQL. I have made 3 tables; 'Shelters', 'Dogs, and 'Breeds'. I have made the XHTML form, for a user to submit their preferred dog details into. When they click submit the next page should show all of the dogs within my database that match their choices. How would I go about showing these details? 'IF Checkbox 1 and Checkbox 2, Male Radio Button' are all selected, show dog ID 2, 4, and 6. ^^ How would this be coded in PHP? What I've created so far: http://hermes.hud.ac.uk/u0656983/Dog%20Website/
  15. Hi guys, I'm just getting to grips with PHP. I'm attempting to create a search engine for a Pet Rehoming company. A user selects which shelters they'd like to pick the pet up from along with selecting a preferred breed and sex, the script then shows the user a list of dogs which match the users selections. This site shows exactly what I need to create. http://hermes.hud.ac.uk/u0754700/assign2/ However, like I stated before, I'm still getting to grips and am unsure about the best way to create this. I don't even know where to start, any help would be appreciated.
×
×
  • 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.