0

I have a database table with the following fields: name, company_name, geo_loction. I want to get those fields using the following query.

$zip_code = db_query("SELECT * FROM data_set WHERE id = 1", array(":city" => $city))->fetchObject();

Is that the correct code? How do I show the result?

0

1 Answer 1

3
//here $id value is hard-coded to 1, you can use your own logic to get the value.
$id = 1;
$result = db_query("select name, company_name, geo_location from {data_set} where id=:id", array(':id' => $id));

//To iterate over each row of the resultset use foreach
foreach($result as $ind_data) {
  echo "name is " . $ind_data->name . "<br/>";
  echo "company name is " . $ind_data->company_name . "<br/>";
  echo "geolocation is " . $ind_data->geo_location . "<br/>";
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.