Jump to content

DanielW

New Members
  • Posts

    6
  • Joined

  • Last visited

DanielW's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. HI I've been following a few youtube tutorials and have been playing around with querying databases, however I dont really fully understand whats going on, I've tried to seach on the web for an explination to the code but all I seem to find is more code examples without actully knowing whats happening would someone be able to explain in laymans terms whats happening in this code. sorry for being such a newbie but I like to get to grips and understand how things work $result = mysql_query("SELECT * FROM car WHERE car_model='$car_id'") or die(mysql_error()); $cars = result_to_array($result); foreach($cars as $car){ $car_p=$car['wheel_id']; $result = mysql_query("SELECT * FROM wheel WHERE wheel_id='$car_p'") or die(mysql_error()); $car_wheel_details = result_to_array($result); foreach($car_wheel_details as $car_wheel_detail){ ?> <div class="wheel_stuff"> <h1><?php echo $car_wheel_detail['wheel_name']; ?></h1> <div class="plft"><img src="images/<?php echo $car_wheel_detail['wheel_image']; ?>" /></div> <div class="prt"> <p><strong>Category : </strong><?php echo $car_wheel_detail['wheel_category']; ?></p> <p><strong>Info : </strong><?php echo $car_wheel_detail['wheel_info']; ?></p> <div style="clear:both"></div> </div> <div style="clear:both"></div> </div>
  2. Hi the result of $sqlCommand when I get no results is Tucson which is indeed what i typed for the search
  3. Hi thanks for taking some time to look at my code $searchquersy gets its value from this line $searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']); the value of $sqlCommand when it is being run i not sure I have tried to see in the chrome developer consle but I cannot find what it is, i am pretty new to php
  4. When I search my database I can only get results returned back if I search for only a single letter, when I type a whole word I get 0 matches returned. I have the following if statment where I have been trying to get the correct regular expressions but I am unsure where I am going wrong, What expression would I need to use to be able to type in a city name for example Tucson and get a result? if($_POST['filter1'] == "City") { $sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE city_name LIKE '%$searchquery%'"; //$sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE MATCH (city_name) AGAINST ('searchquery')"; //$sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE city_name REGEXP '%$searchquery%'"; }
  5. ahh thank you, I had been using some video tutorials and they must have been old, I know now where to focus thank you
  6. Hi I am quite wet behind the ears working with php MySQL ect, I have been trying to make a webpage that will search a MySQL database that I have that holds a vareity of information about US States. however when I hit the search button I get the message "No database Selected" ive been trying to figure this out on and off for most of the day. would anyone with more experience be able to see where I am going wrong. Thanks connect.php <?php $dbConnect = array('server' => 'localhost', 'user' => 'root', 'pass' => '', 'name' => 'states2014' ); $db = new mysqli($dbConnect['server'], $dbConnect['user'], $dbConnect['pass'], $dbConnect['name'] ); echo $db ->host_info; echo "<br>"; echo $db ->connect_errno; echo "<br>"; if($db->connect_errno>0) { echo "Database Connection Error".$db->connect_error; exit; } ?> search.php <?php $search_output = ""; if(isset($_POST['searchquery']) && $_POST['searchquery'] != "") { $searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']); if($_POST['filter1'] == "City") { $sqlCommand = "SELECT city_id, city_name AS city_name FROM city WHERE city_name LIKE '%$searchquery%'"; } else if($_POST['filter1'] == "Attractions") { //$sqlCommand = "SELECT city_id, city_name AS city_name FROM city WHERE city_name LIKE '%$searchquery%'"; } else if($_POST['filter1'] == "Famous_Person") { //$sqlCommand = "SELECT city_id, city_name AS city_name FROM city WHERE city_name LIKE '%$searchquery%'"; } include_once("connect.php"); $query = mysql_query($sqlCommand) or die(mysql_error()); $count = mysql_num_rows($query); if($count > 1) { $search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />$sqlCommand<hr />"; while($row = mysql_fetch_array($query)) { $city_id = $row["city_id"]; $city_name = $row["city_name"]; $search_output .= "Item ID: $city_id - $city_name <br/>"; } // close while } else { $search_output = "<hr />0 results for <strong>$searchquery</strong><hr />$sqlCommand"; } } ?> <html> <head> </head> <body> <h2>US States Info</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Search For: <input name="searchquery" type="text" size="44" maxlength="88"> Within: <select name="filter1"> <option value="City">City</option> <option value="Attractions">Attractions</option> <option value="Famous_Person">Famous_Person</option> </select> <input name="myBtn" type="submit"> <br /> </form> <div> <?php echo $search_output; ?> </div> </body> </html>
×
×
  • 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.