Jump to content
xisto Community

ssp2010

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. Thanks bennet for taking the time and helping me out. I've tried what you yold me on the last post, im stuck now where im in the script to display the results . Heres my MSQL I've created a DB called 'cars'.under cars i've created the table vehicles and heres what I created under vehicles......Create table vehicle(id mediumint unsigned not null auto_increment,make varchar(10)not null,description varchar(4000) not null,primary key (id));I've populated the vehicle table with different cars .I'm not sure if you still can see my search form and script page but here it is again just in case you can't view itHeres the search form page<h1>Cars 4 Sale</h1> <form action="sresults.php" method="post"> Choose search type:<br/> <select name="searchtype"> <option value="acura">acura</option> <option value="ford">ford</option> <option value="honda">Honda</option> <option value="lexus">Lexus</option> </select> <br/> Search Vehicle: <br/> <input name="searchterm" type="text" size="40"/> <br/> <input type="submit" name="submit" value="Search"/> </form>__________________________________________________________________Here's the php page I'm having problems with the looping and how I want the results to be displayed. Lets say I want the user to be able to select "honda" also being able to type in what specific model for "honda" they are searching for and have the results displayed if they do not type anything in the box and select still honda they will get everything thats under honda. Heres the php script again I have so far. Can you show the way you would code in the search results and let me know if there is anything missing? thanks<?php// create short varilable names$searchtype=$_POST['searchtype'];$searchterm=trim($_POST['searchterm']);if(!searchtype || !searchterm){ echo 'You have not entered any search details.'; exit;}if(!get_magic_quotes_gpc()){ $searchtype=addslashes($searchtype); $searchterm=addslashes($searchterm);}@$db=new mysqli('localhost','root','********', 'cars');if(mysqli_connect_errno()){ echo 'Error: could not connect to database'; exit;}$query="select make, description from vehicle where make= ??????? (im not sure how to pick honda only or acura etc from the field 'make' in the table 'vehicle' ".$searchtype." like '%".$searchterm."%'";$result=$db->query($query);$num_results=$result->num_rows;echo "<p>Number of cars found: " .$num_results."</p>";for($i=0; $i<num_results; $i++){ $row=$result->fetch_assoc(); echo "<p>Vehicles." (i+1) (also stuck how to display everything here ) }$result->free();$db->close();?>
  2. Hi, guys thanks for the reply. Bennet i've tried what you've told me which makes more sense by adding the makes in one table. The thing is now when I try to populate the table, say i want to add a car under only "honda" and the "description" field. MYSQL gives an error saying "field 'acura' doesnt have a default value." I'm trying to get the select drop downs or the search box to find only the information being selected from the table and not the other makes. ;Here's what I've been working, I don't know if it will help much. ________________________________________________________________________________________________________ (here's the search form) <body> <h1>Cars 4 Sale</h1> <form action="sresults.php" method="post"> Choose search type:<br/> <select name="searchtype"> <option value="acura">acura</option> <option value="ford">ford</option> <option value="honda">Honda</option> <option value="lexus">Lexus</option> </select> <br/> Search Vehicle: <br/> <input name="searchterm" type="text" size="40"/> <br/> <input type="submit" name="submit" value="Search"/> </form> </body> _________________________________________________________________________________________________________________________________________ (here's the php script to search the database..) body> <h1> Local Cars 4 sale</h1> <?php // create short varilable names $searchtype=$_POST['searchtype']; $searchterm=trim($_POST['searchterm']); if(!searchtype || !searchterm){ echo 'You have not entered any search details.'; exit; } if(!get_magic_quotes_gpc()){ $searchtype=addslashes($searchtype); $searchterm=addslashes($searchterm); } @$db=new mysqli('localhost','root','*********', 'cars'); if(mysqli_connect_errno()){ echo 'Error: could not connect to database'; exit; } $query="select * from vehicles where ".$searchtype." like '%".$searchterm."%'"; $result=$db->query($query); $num_results=$result->num_rows; echo "<p>Number of cars found: " .$num_results."</p>"; for($i=0; $i<num_results; $i++){ $row=$result->fetch_assoc(); if($searchtype=="honda"){ echo "<p>".($i+1).($row['honda'])."</p>"; }elseif($searchtype=="ford"){ echo "<p>". ($i+1).($row['ford'])."</p>"; }elseif($searchtype=="lexus"){ echo "<p>". ($i+1).($row['lexus'])."</p>"; }elseif($searchtype=="acura"){ echo "<p>". ($i+1).($row['acura'])."</p>"; }else{ echo"<p> no search was entered</p>"; } } $result->free(); $db->close(); ?> </body>
  3. Hi guys im new to php and mysql and have a problem that the book im using and online manual doesn't seem to help me with or I might be overlooking it. Here's the deal I've created a few tables (acura,honda,lexus etc.....)under a datatbase called "cars" . under the tables are categories such as userid,make and model , and a description . I've created a search form with drop down selects and a search box to search the database. What I cant get accomplished is when a user clicks on a automobile it does not show the results from the database. I've tried many ways to figure this out and read alot of forums and still have no luck. I want a user to be able to select a maker "honda" or any other and be able to find everything that is in the honda table or if they want to be more specific such as search for a "04 civic" under honda they can do so by typing it in the search box. Can someone please show me the easiest way to do this by showing how its done exactly from the html form to the php script? I'd greatly appreciate it. thanks
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.