title: How get data from mySQL using string with params?
body: <p>I've iOS App which should receive JSON data from MySQL database using string with parameters and PHP script. String looks like this: NSString *getDataURL1 = [NSString stringWithFormat:@"<a href="http://myhost.com/jsoncar.php?carOne=%@" rel="nofollow">http://myhost.com/jsoncar.php?carOne=%@</a>", _carOneToServer]; where _carOneToServer is string containts particular car model which user has selected in my App, for example "AUDI A3 1.8TFSI". In MySQL database I've got exactly same car model.</p>
  
  <p>PHP script should be checking for matching models between ULR query and MySQL data base and returns parameters for this car model.</p>
  
  <p>So far I wrote some code but it returns []. I understand I need variables to work with, but I don't know PHP, so need your help guys. Thank you.</p>
  
  <p>PHP script:</p>
  
  <pre><code>$host = "localhost"; //Your database host server
  $db = "MyDataBase"; //Your database name
  $user = "user"; //Your database user
  $pass = "password"; //Your password
  
  
  $connection = mysql_connect($host, $user, $pass);
  //Check to see if we can connect to the server
  if(!$connection) {
  die("Database server connection failed.");
  } else {
      //Attempt to select the database
      $dbconnect = mysql_select_db($db, $connection);
  
      //Check to see if we could select the database
  if(!$dbconnect) {
      die("Unable to connect to the specified database!");
      } else {
  
  
          if (isset($_GET['carOne'])) {
  
      $carModel = $_GET[carOne];
  
          $query = "SELECT carFuelEconomy, carPurchasePrice FROM cars
      WHERE carModel = $carModel";
          $resultset = mysql_query($query, $connection);
          $records = array();
  
  //Loop through all our records and add them to our array
      while($r = mysql_fetch_assoc($resultset)) {
          $records[] = $r;
          }
  //Output the data as JSON
  echo json_encode($records);
  }
  }   
  }
  </code></pre>
  
  <p>MySQL database:</p>
  
  <pre><code>CREATE TABLE cars
  (
  
  id INT PRIMARY KEY NOT NULL auto_increment,
  carModel VARCHAR(255),
  carFuelEconomy int,
  carPurchasePrice int,
  distanceTraveledDaily int,
  lenghtOfOwnership int
  
  );
  
  -- Insert data into our table
  
  INSERT INTO cars(carModel, carFuelEconomy, carPurchasePrice, distanceTraveledDaily, lenghtOfOwnership)
  VALUE ('AUDI A3 1.8TFSI', 27, 30795, 30, 76);
  
  INSERT INTO cars(carModel, carFuelEconomy, carPurchasePrice, distanceTraveledDaily, lenghtOfOwnership)
  VALUE ('AUDI A3 2.0TDI', 36, 33495, 30, 76);
  
  INSERT INTO cars(carModel, carFuelEconomy, carPurchasePrice, distanceTraveledDaily, lenghtOfOwnership)
  VALUE ('AUDI A3 2.0TFSI', 33, 34095, 30, 76);
  </code></pre>